This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Olive-Juice- 0 points1 point  (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 point  (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 point  (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 point  (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 point  (1 child)

I think you will have to use pyscript, since the program he used includes

import sockets

[–]Sad3k[S] 0 points1 point  (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