Goodmorning, I’m trying to run a python script inside automations.yaml but it does not work and I would ask help. I write down the lines I wrote until now.
configurations.yaml:
switch:
- platform: rpi_gpio
ports:
13: luci
invert_logic: true
shell_command:
hello_world: 'python3 /config/python_scripts/hello_world.py'
python_script:
hello_world: /config/python_scripts/hello_world.py
automations.yaml:
- alias: Luci
initial_state: 'on'
trigger:
platform: state
entity_id: switch.luci
to: 'on'
for:
milliseconds: 500
action:
- service: switch.turn_off
entity_id: switch.luci
- service: notify.notify
data:
message: "luci"
- alias: test
trigger:
- minutes: "/2"
platform: time_pattern
action:
- service: python_script.hello_world
data:
entity_id: switch.luci
- service: notify.notify
data_template:
message: " SpeedTest, download speed = {{ states('sensor.speedtest_download') }} MB/s. "
message: "invio"
instead of
- service: python_script.hello_world
data:
entity_id: switch.luci
i tryed with the following but it not work too:
- service: shell_command.hello_world
/config/python_scripts/hello_world.py:
import datetime
entity_id = data.get("entity_id")
if entity_id is not None:
service_data = {"entity_id": entity_id}
hass.services.call("switch", "turn_on", service_data, False)
f = open("/config/python_scripts/test.txt","a")
f.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
f.write("\n")
f.close()
Can someone help me to understand why it not work?
thank you