offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

NFC Tags in Home Automation

The current Zemismart curtain roller started to act up and I was to do the whole reset with a pin and a button, but my manual was in a box in our storage so I had to retrieve it like Conan the Barbarian. I had to shuffle other boxes and stuff to get to the one I needed. This just made me realize that our physical storage space could use some more love. I thought it would be a great idea to put an NFC tag near the curtain to have a link to the scanned manual instead. Get rid of all the paper forms and have a digital storage of things would free up the space. I already use Syncthing for the photos for the PhotoPrism so I might as well do a self-hosted document storage system to manage general files, too. For that, I opted to use dufs. It's simple and it works. I mounted a folder from my external drive into the configuration of dufs, added the credentials and left it in the local network. After all, I don't need this service exposed to the whole world to see. I added the whole thing into my existing compose file on the Raspberry Pi. It is something like this:

dufs:
  image: sigoden/dufs
  ports:
    - 5000:5000
  volumes:
    - /path/to/host/folder:/data
  command: ["/data", "-A", "-a", "user:pass@/:rw"]

Of course, you'd need to adjust where necessary for your system. With static file serving in place, I scanned the manual and uploaded the resulting file to the dufs.

I did the same for the washer/dryer, but it was easier for it. I found three manuals online and uploaded them in a single folder. I could eventually write the folder URL to the tag instead. One piece of the puzzle was in place. Moving on to the NFC one.

When discussing my solution with friends, they asked a few questions about the NFC itself. I answered them as best as I could:

  1. Do the NFC tags require batteries?

    No, they're just a chip and an antenna in a small form. When exposed to the RF field, they emit the data. They do not require batteries which is cool. The reading happens when the reader and the tag are in a close proximity of each other.

  2. Could you do the same with QR code if you're scanning with your phone?

    Yes, you could embed the data and this is wonderful. WeChat and Revolut even function with payments reading the QR codes since you only need a camera. Almost all smartphones have a camera, and while majority of phones do have NFC, it's not as ubiquitous as the camera. When you create a tag in Home Assistant, you get a QR code, but can also write it to an NFC chip. I had the QR code for one automation already and I also use one currently for WiFi credential listing in the apartment as well, but in my experience, scanning QR codes requires more work from the user and more time is spent, whereas NFC scanning happens almost instantly.

  3. You could call automations by just clicking a shortcut on your phone.

    Yes, I could, and I do for some of the things. Curtain control mostly. But then you have to set up phone shortcuts as well.

  4. You can tell your smart speaker to execute an automation, right?

    I can, and I do. A smart speaker leaves a lot to be desired, though, at least the Nest Mini I have. It mishears the command or ignores it for some reason or says it did things, but it didn't... It even asked me to clean my room myself once instead of sending the vacuum cleaner there. Can you imagine?

  5. What do your cats have to do with that technology?

    Nothing except having the same acronym. NFC = Near Field Communication, NFC = Norwegian Forest Cat

Last year I bought a box of NFC NTAG 215 tags and started using them in various circumstances. I gave some to friends as well so they can experiment if they wanted to. While reworking the dashboard for the Home Assistant instance, I made the tabs for each room of the apartment and in each room I opened a markdown card describing what NFC tags I had in each room (or in general) and what they were used for.

  • on the keychain:

    holds the URL of the OffSetLab

  • on the cork board:

    has 7 tags and acts as a dashboard for controlling the lights and sounds for the D&D session

  • on the projector:

    toggles projector, speakers, PS4 on/off state and lowers the motorized projector screen (for some reason, HDMI CEC is not powering on all the devices so I have to trigger them each separately)

  • on the washing machine (two tags):

    triggers a notification in 8:05 hours from the moment of scanning. This is the exact time the washing machine cotton 40 °C and cupboard dry takes to finish. I might have a smart washing machine one day so I would not be limited to the manual notification of that single program

    contains the link to the folder with manuals for the washer/dryer

  • below the kitchen hanging cupboard:

    calls Roborock to clean up the kitchen. This is useful when the surfaces are cleaned up and crumbs thrown on the floor

  • on the apartment door:

    WiFi connection information for the apartment. There's a QR code next to it as well. When guests arrive and ask for a WiFi access, this is how they get it

  • on the hooded litterbox:

    turns off the notification annoyer to clean the litterboxes

  • on the side of the mirror next to the bathtub:

    toggles a scene which dims the lightbulb, changes its colour to warm and turns on the fan

  • on the blue box in the storage:

    sends a notification to the phone that scanned it with a list of items in the box (I should change this to a proper link to a list)

  • on the window

    contains the link to the manual for the roller curtain motor

Vesna particularly loves the physical dashboard with NFC tags I made for our D&D sessions. They start playing ambiental music from Spotify playlists on the speakers and manipulate the lights as well as one that turns off everything that was running for the session. I started up the Inkscape, added one inch diameter circle, only border, no fill and placed the icon from Material Design Icons inside it. I printed it on the sticky paper and cut it out to be on the NFC tag. Then I put the tags onto the hexagonal cork board and gave it to Vesna to play with the dashboard since she's our resident dungeon mistress (not that kind, you perverts).


/media/images/ha-dnd-dashboard.jpg

Setting up the NFC tags is quite easy:

  1. Take an NFC tag and have it ready
  2. Open Home Assistant app on your NFC enabled phone
  3. In Home Assistant, open the hamburger menu, pick Tags, click Add Tag, name it and press create and write (you don't have to enter tag ID)
  4. Press the robot head icon for the created tag, this creates the automation that triggers When a tag is scanned
  5. Create the automation according to your needs

/media/images/ha-app-tags.png

Alternatively to the Home Assistant app, you can use NFC Tools app, go to Write -> Add a record, pick a type of the record and follow the instructions. This is useful for having the tag with other data like links, WiFi credentials, automating phone behaviour with Tasker... in essence, things that are not exclusive to Home Assistant.

Automations in the house are either:

  • togglers whose action is Conditionally execute an action and default to another action which is using a simple IF-THEN-ELSE construct to check for a certain device state (off or on) and execute a script. This enables me to activate things or deactivate them

  • use the same thing as above, but check which device triggered it. IF part is: Test if template renders a value equal to true:

    {{ trigger.event.data.device_id == "my device app id taken from device's URL" }}
    

    THEN is Call a service: 'Notifications: Send a notification via mobile_app' (depending on the device, I have two actions for two devices here so it's going to two different mobile_app instances). No ELSE.

  • directly Call a service (usually execute a script or send a command to a device) or Delay for, then Call a service (in the case of the washing machine tag)

Annoyer silencing is a bit complex, so I'll explain it as best as I can with an example for my litter box cleaning routine. It comprises of one helper and three automations to accomplish the entire workflow:


/media/images/ha-helpers.png
  1. Under Settings, Devices and services, there is a Helpers tab. I use the toggle type which is esentially an input boolean. It can be either true or false. I called it "Litterbox Cleaned".

  2. I have an automation that triggers every half an hour, three times. It's active in the morning, in the afternoon and in the evening. Annoying, right? I call it "Litter Boxes Notification". It checks if the "Litterbox Cleaned" is Off, and only then does actions that are:

    1. Call a service 'Notifications: Send a notification via mobile_app' with the message: "Clean the litter boxes." and data:

      actions:
        - action: SILENCE
          title: Silence
      

      This means that the notification on the phone will have a button that can be pressed and the specified action triggers.

    2. Text-to-speech (TTS) 'Say a TTS message with cloud' (I edit this one in YAML because I use a template to give some personality to the responses):

      service: tts.cloud_say
      metadata: {}
      data:
        cache: false
        entity_id: media_player.my_nest_speaker
        message: >-
          {{ ["Clean the litter boxes.", "Please clean the litter boxes.", "Clean the fucking litter boxes.", "Roses are red, violets are blue, clean the damn litter boxes, so I don't bother you.", "Did you clean the litter boxes?"] | random }}
      
  3. Manual interventions are then another automation that I call "Tag Litterbox 1 is scanned" and it has two triggers:

    1. When a tag is scanned (the one I physically put on the litter box)

    2. When mobile_app_notification_action event is fired. Event data is action: SILENCE which means I pressed the silence button on the notification from the step 2.1.

      And two actions:

      1. Call a service 'Input boolean: Turn on' on Litterbox Cleaned

      2. Call a service 'Notifications: Send a notification via mobile_app' (I edit this one in YAML because I use a template to timestamp the silencing):

        service: notify.mobile_app_fp3
        data:
          message: Litterboxes cleaned at {{ now().strftime("%-I:%M %p (%d-%m-%y)") }}.
        
  4. The last automation I call "Turn Off Litterbox Input" and it triggers on the time as well, five minutes after the last notification in the series. The automation from step 2 triggers on 10:00, 10:30, 11:00, and this one triggers on 11:05. It has the action Call a service 'Input boolean: Turn off' on Litterbox Cleaned. This makes the helper have a value of false and it's idempotent so there's no worry if it's already off. This action primes the annoyer for the next series of annoying that will start in the afternoon (again, automation from step 2).


/media/images/ha-automation-lbn.png
/media/images/ha-automation-lb1is.png
/media/images/ha-automation-tolbi.png

I use Nabu Casa cloud connection for the convenience of accessing the instance outside my network, to integrate with voice assistants easily and to financially support Home Assistant development. I think this is a good thing. With it, I'm able to have tts.cloud_say, but you could also use tts.google_translate_say if you have a different setup.

This was a long overdue article (and it's long, too) so I hope it's useful for whomever is reading this, but it will be useful to me so I remember how I did stuff. Poking around the Home Assistant is not a scary experience and it can be very fun.