Using NFC Tags to create automations in Home-Assistant & Node-red

Using NFC Tags to create automations in both Home-Assistant & Node-red

So this was something I’d been looking at doing for a long time. A while back I bought a load of NFC tags on Amazon for use in some projects around the house. Up until now, I’d struggled to see the use case for many of them as quite frankly, we’ve been putting voice assistants to good use. The fact that I’ve been able to create custom entities and flows with Google and Alexa has allowed me to literally set up whatever I wanted. However, I was keen to give these a try.

10 NFC tags (amazon- affiliate link)

10 NFC tags (Aliexpress)

I’ve recently purchased a variety of Reolink Cameras to trial and play with. You can read more on that here. I have used the wireless camera to provide monitoring for an old diesel boiler that we’ve been using. We are currently living on a mountain where there is no gas, so diesel it is unfortunately. Recently, one of the pumps got blocked and we suffered a fuel leak. I have put the wireless Reolink into action monitoring the situation from a far. At night though, we need to use the IR lights to be able to see anything. Note, I’m using this to monitor, not from a security perspective. Thus I don’t leave the IR lights on all the time. The main reason, is because it attracts spiders, and unfortunately, spiders are my kryptonite! I can’t stand the little buggers. So I came up with this solution.

I’ve integrated the Reolink cameras into Home-Assistant using a custom add-on you can find here. It works perfectly, and exposes the various attributes of the camera directly into lovelace.

IR light toggle in Home-Assistant
IR light toggle in Home-Assistant

Tags in Home-Assistant

I set about creating a simple automation to turn the IR lights on for 1 minute when the NFC tag is scanned, and then off again, so as not to give the spiders any excuse to create their love nest in our boiler room. In order to start this, I opened the Home-Assistant app on my phone, and went to App Configuration -> NFC

Mobile App NFC Menu
Mobile App NFC Menu
Mobile App Read / Write Tag
Mobile App Read / Write Tag

 

Click on “write tag” and then hover over the tag you want to use. It will come up with some JSON once it’s read it. You can put the phone down now and go over to your desktop/laptop and access your Home-Assistant interface. Go to Configuration -> Tags and there you should see an entry for the tag you just scanned.

Newly Created Tag Entitiy
Newly Created Tag Entitiy

Click on the little robot head on the right which will take you to the automations screen. Here I’ll just show you what I have filled in, rather than try and talk you through each step.

In a nutshell, scan the tag, the IR lights come on, then after 1 minute the lights go off. This will only work between sunset and sunrise, i.e. when it’s dark.

Automation Part1: Trigger
Automation Part1: Trigger
Automation Part2: Action
Automation Part2: Action

One thing you need to be aware (Thanks to Pete Guy for his help on this!). When trying to add the time (sun) conditions, you need to add two separate entries. I originally just had after sunset and before sunrise on the same condition and it refused to work. You need to edit some yaml here unfortunately.

We need to edit the automation in Yaml;
We need to edit the automation in Yaml;

We need to combine the conditions using OR.

WHy we use OR
Why we use OR
Combining the conditions in YAML using OR
Combining the conditions in YAML using OR

Once complete, save the automation and scan the tag (as long as it’s dark). Job done.

So keep this in mind when looking at doing your automations in Home-Assistant. Thankfully, there’s more than one way to skin a cat! Let’s take a look at Node-red.

Tags in Node-Red

Ok, so it’s still in beta but it’s working perfectly well. In Node-red as long as you have the Home-Assistant palette, which I’m assuming you all do, you can drag out the Tag node and take care of the automations from there.

Tag Node in the Home-Assistant Palette
Tag Node in the Home-Assistant Palette

One thing to keep in mind. Make sure you add a name to the tag in Home-Assistant. Initially I couldn’t see the tag in Node-red, no matter how many times I updated the tag list or restarted the server etc. When you bring the tag into Home-Assistant initially it has that long identifier. I thought that was enough, but for the Node-red flow to work, I needed to add a name to it. Once done, i updated the tag list and it popped in immediately.

Adding a name to the tag in home-asssitant
Adding a name to the tag in home-asssitant
Adding the tag to Node-Red
Adding the tag to Node-Red

 

Just for checking, i attached it to a service call node and am using it to toggle a sonoff basic on and off. Everytime I tap the NFC tag with my phone, the light toggles on and off. (I showed the full flow for completeness). If you’re not up to speed with Node-red and want to get started I have a 3 part tutorial which might help. If you’ve not even got it set up yet, well I have you covered too. See below for the links:

  1. The Beginner’s Guide to Node-red with Home-Assistant (Part 1: MQTT)
  2. The Beginner’s Guide to Node-red with Home-Assistant (Part 2: Switch Node)
  3. The Beginner’s Guide to Node-red with Home-Assistant (Part 3: Timers)
  4. Basics: Connecting Home-Assistant to Node-red
Simple automation to toggle a light switch
Simple automation to toggle a light switch

If I was going to replicate the Home-Assistant automation in Node-red, this is what I would be going for:

Replicating the Automation in Node-red
Replicating the Automation in Node-red

Summary

Going forwards, I would probably use Node-red for the automation side of things but I wanted to try it both ways. I can add the time condition (i.e. when dark) in the same way I did here with my nightlight.

Now I’m trying to think what else I can use these for. I thought maybe to put one in the car. Thinking that as we pull up to the drive, we can tap the phone on the dashboard to turn some lights on etc according to the time of the day. Now that I’ve set up tailscale, I have permanent access to my Home-Assistant installation where ever I am, so there’s no stopping me!

 

If anyone else has got any other ideas where these would be better than a simple voice command, pop them in the comments, or in our facebook group.

https://www.facebook.com/groups/386238285944105

If you’re considering a renovation and looking at the structured wiring side of things, or maybe you just want to support the blog, have a look below at my smarthome book, it’s available in all the usual places (including paperback)!

The Smarthome Book
The Smarthome Book

 

 

Leave a Reply