Python as a trigger to home assistant?

My question is can I make a python project on a server/pc run and send some sort of trigger to home assistant. I don’t want to run the python script on my raspberry pie, I just want like a line of code in the python program to send a trigger to home assistant.

One way I can think of is to create a helper (input_*) in HA and then update it’s state via the HA REST API. You can then trigger an automation on the helper’s state change. You will need to reset that state then at the end of that same automation or via the API if you want to be able to trigger it again.

1 Like

I do this with several of my projects around the house and I use my python code to send MQTT messages and then HA gets the MQTT messages. This is not unlike a REST sensor but I find it easier to deal with in code. I do use REST sensors also for some off the shelf components.

1 Like

Thanks a lot, using the restful API worked for me!

You make a good point about using MQTT. That would be another way: create an HA sensor on a topic and produce to that topic with the script. There will be pros and cons.

Just want to point out that I wasn’t referring to the REST sensor or platform, but the HA server API. OP wants to push, not pull.

Glad it did!

Just because I thought of it, here’s another way: I think you can also emit a custom event via that API and you can then trigger an automation on that. Might be nicer if you don’t want to keep state on the HA side (get rid of that helper) and then there’s nothing to turn off.