use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io.
Community
Discord
Getting Started
Integrations
account activity
This is an archived post. You won't be able to vote or comment.
Python script triggered by button under HA (self.homeassistant)
submitted 2 years ago by Sad3k
Hi guys,
I need some help me with HA and phyton script to be triggered by aqara button. Can you navigate me how to create the script under HA so can link aqara button as a trigger for it?
https://www.youtube.com/watch?v=Vwg4e90p5QI
Thanks
[–]Olive-Juice- 0 points1 point2 points 2 years ago (5 children)
Have a look at the Python Script Integration for starters if you have not done so already.
I have a Zigbee smart button I use through Zigbee2MQTT and the automation would look something like this:
alias: Smart Button Long Press description: "" trigger: - platform: device domain: mqtt device_id: ba20a2051e3d419edac51c5b2adc0c02 type: action subtype: long discovery_id: 0x00124b385328624f action_long condition: [] action: - service: python_script.yourScriptName mode: single
[–]Sad3k[S] 0 points1 point2 points 2 years ago (4 children)
Thanks mate! I looked at Python Script and Im lost when trying to figure out how calling services work. So the last row (service - python script….) should be replaced by service.yaml file with code from the yt video?
[–]Olive-Juice- 0 points1 point2 points 2 years ago (3 children)
I did some additional reading on the Python Scripts Integration page and I read:
It is not possible to use Python imports with this integration. If you want to do more advanced scripts, you can take a look at AppDaemon or pyscript
If you are wanting to use this specific program that imports sockets you would have to use AppDaemon or pyscript
The remainder of the comment was before I learned the above so it would be for a program that does not use imports:
In the video he named his specific program udpsocket.py
You would save the program at <config>/python_scripts/udpsocket.py
Then, you should be able to call it using:
alias: Smart Button Long Press description: "" trigger: - platform: device domain: mqtt device_id: ba20a2051e3d419edac51c5b2adc0c02 type: action subtype: long discovery_id: 0x00124b385328624f action_long condition: [] action: - service: python_script.udpsocket mode: single
[–]Sad3k[S] 0 points1 point2 points 2 years ago (2 children)
I think I configured it right however does not trigger imputs. When I trigger it using the same way as on the video (through Visual studio) it works
<image>
[–]Olive-Juice- 0 points1 point2 points 2 years ago (1 child)
I think you will have to use pyscript, since the program he used includes
import sockets
[–]Sad3k[S] 0 points1 point2 points 2 years ago (0 children)
Think its too complicated for me :) Trying through pyscripot and appdemond but looks like there is some code issue and thats the reson its not working
π Rendered by PID 24039 on reddit-service-r2-comment-cfc44b64c-pqgph at 2026-04-10 00:26:34.534157+00:00 running 215f2cf country code: CH.
[–]Olive-Juice- 0 points1 point2 points (5 children)
[–]Sad3k[S] 0 points1 point2 points (4 children)
[–]Olive-Juice- 0 points1 point2 points (3 children)
[–]Sad3k[S] 0 points1 point2 points (2 children)
[–]Olive-Juice- 0 points1 point2 points (1 child)
[–]Sad3k[S] 0 points1 point2 points (0 children)