Question: Firing Home Assistant commands from external Python script?

Hey there, sorry for the potentially noob question.

I’ve been a long time lurker, and huge fan of this community - I’m hoping to get a bit more involved now that I’ve figured out some of my way around HA and got most of my system running. I’ve currently got a lovelace setup and floorplan, with a bunch of features and automations, having far too much fun.

Anyways, I have an NFC chip implanted in my hand that I use (on top of some other functions) to unlock my front door and desktop. My desktop is unlocked (note: user must already be logged in, so python script can be running in the background, but this is ok, my computer usually stays on) via a python script I wrote, that authenticates my tag. I’m now hoping for a way that I can also turn on my office lights, once this script authenticates a tag. So either this python script fires a command to home assistant (running on a separate Pi), or HAssistant somehow listens to this script??

I’ve got Compsci experience, mostly in Frontend and Database dev, but I seemed to have hit a small block on this problem, and I’m not sure the best route of moving forward. Any and all help would be appreciated :slight_smile:

Also, while I’m here - Is there something I should be doing as a first time poster? Like a welcoming forum post or is there etiquette to posting your projects or something?

Yes, you must buy us a beer! :rofl:

Welcome to HA!
I think you can use the API for this, or what i’m doing, is to publish some payload to mqtt and let HA react on the payload with mqtt sensors.

2 Likes

Some of us do not drink alcohol. Be sure to add a non-alcoholic selection too. :wink:

@VDRainer lol, if I happen to run into another HA enthusiast somewhere, then beers are definitely on me :wink:

The API is EXACTLY what I was looking for! Getting a “401:Unauthorized” error at the moment, but at least I’m on the right track. Thanks a bunch

Update for anyones future reference:

Using the API worked flawlessly, and was really easy to implement - took less than an hour all said and done. Now, when I walk to my front-door and scan my implanted NFC chip, the bayesian probability of my presence is updated (even if my phone hasn’t connected to WiFi or pinged bluetooth yet). This sets the house into ‘Home’ mode, which turns on most of the lights in the main living quarters. My office however stays off, until I walk in and scan the NFC reader near the doorway - this unlocks my computer and turns on my office lights for me. When motion is not sensed in the room for 30 minutes, it locks my computer and shuts off the office lights :slight_smile: Loving the fact that I can now integrate the authentication from my NFC implant with my HA system!

2 Likes

Sounds interesting.
Could you provide some links to the NFC and Reader?

1 Like

For Sure!

Chip: https://store.dangerousthings.com/product/xnt/
Reader: https://www.amazon.ca/gp/product/B0797J7M6P/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
Short Video I did on FAQ about the implant: https://www.youtube.com/watch?v=5tCyVfcFOG0

1 Like

Cool! Thanks a lot!

1 Like