test the script service, I have the hello_world.py example
name = data.get('name', 'world')
logger.info("Hello {}".format(name))
hass.bus.fire(name, { "wow": "from a Python script!" })
I call it from the developer tools with { “name”:“you”} and it works.
So now I was trying to create a call to the service from an automation and I don’t have the syntax right. (hassctl config chokes)
what should my action look like?
Here is what I have now …
- alias: test script
trigger:
- platform: template
value_template: "{% if not is_state('input_select.thermostat_mode', 'off') %}true{% endif %}"
action:
- service: python_script.hello_world
name: Paul
Getting close. I switched my literal for variable or at least I thought. It did not evaluate, but passed as a literal.
Here is where I am at right now …
- alias: test script
trigger:
- platform: template
value_template: "{% if not is_state('input_select.thermostat_mode', 'off') %}true{% endif %}"
action:
- service: python_script.hello_world
data_template:
{ "name": trigger.to_state.state }
trigger.to_state.state, I would have expected to be Cool, Heat, or Auto depending on the input_select.
So I have 3 automations and all three fire the first time, but then only one fires after that
Here is the log, you can see it at the end.
2017-07-12 15:13:05 INFO (Dummy-12) [homeassistant.components.zwave] Z-Wave network is complete. All nodes on the network have been queried
2017-07-12 15:13:05 INFO (Thread-1) [homeassistant.components.zwave] Z-Wave ready after 5 seconds
2017-07-12 15:13:05 INFO (Thread-1) [homeassistant.components.zwave] Z-Wave polling interval set to 60000 ms
2017-07-12 15:14:05 INFO (MainThread) [homeassistant.components.automation] Executing Set Thermostat Mode On
2017-07-12 15:14:05 INFO (MainThread) [homeassistant.components.automation] Executing Set Thermostat Mode
2017-07-12 15:14:05 INFO (MainThread) [homeassistant.components.automation] Executing test script
2017-07-12 15:14:05 INFO (Thread-9) [homeassistant.components.python_script] Executing hello_world.py: {'name': 'Heat'}
2017-07-12 15:14:05 INFO (Thread-9) [homeassistant.components.python_script.hello_world.py] Hello World Started
2017-07-12 15:14:05 INFO (Thread-9) [homeassistant.components.python_script.hello_world.py] Hello Heat
2017-07-12 15:14:18 INFO (MainThread) [homeassistant.components.automation] Executing Set Thermostat Mode
2017-07-12 15:14:30 INFO (MainThread) [homeassistant.components.automation] Executing Set Thermostat Mode
2017-07-12 15:14:43 INFO (MainThread) [homeassistant.components.automation] Executing Set Thermostat Mode