Logo

dev-resources.site

for different kinds of informations.

Creating NFC Or QR Code Automations In Home Assistant Using Webhooks

Published at
3/26/2024
Categories
homeautomation
smarthome
webhooks
nfc
Author
danielrosehill
Author
14 person written this
danielrosehill
open
Creating NFC Or QR Code Automations In Home Assistant Using Webhooks

Home Assistant has a built-in NFC tag creator. But it also offers the means to create NFC tags through a different method: utilising webhooks.

Why might you want to do this?

You may (deliberately!) want to allow anyone in your home the ability to trigger automations (including guests who aren't on your system).

  • Currently, the NFC Tags functionality doesnā€™t support creating tags on the desktop. Personally, I think that this is an unfortunate omission. Like most things, I find using destkop applications to create NFC tags much quicker than replicating the action on a smartphone (to do this, youā€™ll obviously need a USB NFC reader/writer).

  • You can keep a list of your webhook URLs. The trigger that makes this work is visible.

  • You might want to use this method as a chance to explore webhooks generally.

  • If you want to use scanable barcodes to create automations you might want to use a symbology other than QR (like DataMatrix or PDF417). We can create and design our own stickers this way.

You might just want to do things a little bit differently!

How To Create The NFC Tags (Or Barcodes)

Hereā€™s how to set this up:

In ā€˜Automationsā€™ set your trigger to be a webhook.

Image description

But donā€™t stick with the default settings.
Turn on ā€˜GETā€™ and (this is my recommendation) preserve ā€œOnly accessible from the local networkā€ (GET is required for the webhook to be trigger-able from a browser request; otherwise the webhook is waiting for a POST request).

Image description

Under ā€œThen Doā€ set up whatever you want to automate.

Creating The NFC Tags (Or Custom Barcodes)

Copy the webhook URL once itā€™s been generated onto your clipboard:

Image description

We can now use any program we like to write the tag, whether on desktop or mobile.

I like NFC Tools (it has a nice Linux GUI) but there are plenty of tools:

Image description

Another little security feature I like to add to all my tags is password protection.

This protects the tags against accidental deletion.

A stronger version of this is locking the tags (in NFC Tools this option is only available on the mobile version).

But this is an irreversible action which will prevent anyone (including you!) from ever being able to edit the tags.

If you like the idea of password-protecting your tags, in NFC Tools, jump into 'Other' after writing the payload and select 'Set password':

Image description

For barcodes it's the same idea: we just need to create a barcode with the webhook URL. Here's an idea for one that could trigger an automation that runs a home theatre lighting (and sound) setup. Give it to your friends the next time you're hosting a movie night (and are feeling lazy!).

Image description

The nice thing about creating NFC tags (or barcodes) with webhooks is that (so long as the webhook URLs remain viable) you donā€™t need to edit the actual tags ever again.

If you decide that you want to switch up what the NFC tag does a bit, for example, you can simply make your changes under the Home Assistant automation youā€™ve already set up. The trigger is the same ā€” you just need to change what it does.

You can validate that your NFC-to-webhook automation is running correctly by scanning it with your phone. You should see this pop up from the automation editor:

Image description

If weā€™re talking about automations that trigger lighting changes, it will probably be (visually) obvious that the webhook has succeeded and the automation has worked.

But in cases where there mightnā€™t be a physical indication (letā€™s say you triggered an automation to turn off the lights in one hourā€™s time) you might consider adding a little confirmation notification.

Just add this as an additional action under ā€˜Then Doā€™.

Hereā€™s a little one:

Image description

LAN-Only Webhooks? Or WAN-Accessible Webhooks?

This method works reliably from within a LAN environment, but what if you wanted to create NFC tags that you could scan remotely?

I use Tailscale for remote authentication but it wonā€™t resolve the webhook URLs which begin with ā€œhomeassistant.localā€ (or access homeassistant.local at all for that matter).

Exposing this URL as a subnet route might seem like a logical solution except that it doesnā€™t work that way ā€” subnet routes need to be local IPs and the default Home Assistant installation path looks like a conventional internet address to the tool.

Iā€™m certain thereā€™s a smart way around this but given that I canā€™t envision needing to scan a home automation NFC tag remotely (for the moment) Iā€™m happy to leave finding a solution to this networking quandary on the backburner (of note: the default method doesnā€™t run into this problem. Iā€™m not sure whatever theyā€™re doing but ā€¦ it works).

Other Things You Might Want To Think About

  • For elegance, configure webhooks that redirect to a confirmation URL. Note: I have no idea if this is possible within the confines of HA's current webhooks implementation.

  • Use external webhooks and map them onto internal ones. For this, look into webhook relays.

Some Goofy Use-Case Ideas

(LAN-only webhooks assumed. Some may consider this too insecure. To each their own)

  • Give your friends the ability to run some automations like setting up lighting for a home theatre or getting your apartment into a "party mode" (media center and speakers on, lighting adjusted, etc).
  • Set up your own internal automations
  • Micromanage your friendly neighbour who offered to check on your plants while you're on vacation by demanding that they tap your NFC code when they're done

(I can probably think of many more; the uniting idea is allowing non-authenticated users to change things or notify those in the authentication pool).

homeautomation Article's
30 articles in total
Favicon
The Future of Smart Homes: Top Devices, Trends & Innovations for 2024
Favicon
Tektronix Technologies: Home Automation Experts in Dubai, Abu Dhabi & Beyond
Favicon
Replace Philips Hue automation with Home Assistant's
Favicon
Navigating the Future: Smart Home Innovations and IoT Trends You Need to Know
Favicon
The Home Assistant model
Favicon
Revolutionizing Living Spaces: The Latest in Smart Home & IoT Innovations
Favicon
Revolutionizing Smart Homes: Appleā€™s Bold Step into IoT with Intelligent Innovations
Favicon
Unlocking the Future: Top Smart Home Devices & Trends of 2024
Favicon
Smart Cupboard System with Robotic Arm: Precision and Accessibility in Home Automation
Favicon
Apple's Next Big Thing: Smart Home Displays Set to Change Our Homes in 2025
Favicon
Apple's Game-Changer: New Smart Home Device Set for 2025 Unveiling
Favicon
Unlocking the Future: Exciting Innovations in Smart Home and IoT for 2024
Favicon
Unlocking the Future: Smart Home Breakthroughs and IoT Innovations
Favicon
MajorDom ā€” Your Effortlessly Simple Smart Home, Launched on Kickstarter
Favicon
Smarter Than You Think: NLP-Powered Voice Assistants
Favicon
Building Smart Home Automation with JavaScript
Favicon
Crafting My Perfect Home Assistant Dashboard
Favicon
Raspberry Pi: What you need to know
Favicon
Unlocking Vision: Evaluating LLMs for Home Security
Favicon
Is it Dry Yet?
Favicon
Creating NFC Or QR Code Automations In Home Assistant Using Webhooks
Favicon
Shabbat / Yom Tov Home Assistant Automations ā€” Part 2 (Helper Configuration)
Favicon
Live Average Carbon Intensity rating with Octopus Home Mini in Home Assistant
Favicon
Atom8 Robotic Lab's Comprehensive Home Automation Solutions
Favicon
The Role of LIN Protocol in Smart Home Automation
Favicon
The Future of Smart Homes: How IoT is Changing the Way We Live
Favicon
Adding school morning routine for my son via Homeassistant
Favicon
First Month With My Raspberry Pi
Favicon
How to Control Philips Wiz Bulb Using Go
Favicon
Open-source Sonos apps

Featured ones: