I have an automation whose action is to call a script an pass it data but I can’t for the life of me get it to work, Can anyone point me in the right direction? Here is what I have, obviously it is wrong and some of my different attempts are still showing.
Thanks in advance.
action:
# Only allow a zone to be connected if the previous zone is also connected
- service: script.check_zone_connection_allowed
data_template:
zone_toggled: '{{ trigger.entity_id }}'
previous_zone: >
{% if {{ trigger.entity_id }} == "input_boolean.zone3_connected" %}
input_boolean.zone2_connected
{% elif trigger.entity_id == "input_boolean.zone4_connected" %}
"input_boolean.zone3_connected"
{% elif {{trigger.entity_id}} == "input_boolean.zone5_connected" %}
"input_boolean.zone4_connected"
{% elif trigger.entity_id == "input_boolean.zone6_connected" %}
"input_boolean.zone5_connected"
{% endif %}
Any can be selected but the script will check to make sure there are no gaps in the selected sequence. Zone3 can always be selected because zones 1 and 2 are always on by default and zone 6 can always be deselected because there is no zone 7
Here is the automation that is triggered when any Boolean changes state:
I don’t get an error, it all checks out with the config checker. My problem is how to get the name of the Boolean which triggered the automation into the variable previous_zone which is then passed to the script. I am using a persistent notification to see what happens and zone_toggled gets assigned with the trigger.identity_id.
Here is the script which may or at not do what I hope it will when it is passed the variables.
check_zone_connection_allowed:
sequence:
# Don't allow zone to be shown unless previous zone is shown
# Zone 3 can always be connected
- condition: template
value_template: '{{ zone_toggled != input_boolean.zone3_connected }}'
- condition: template
value_template: '{{ previous_zone == "on" }}'
- service: homeassistant.turn_off
data_template:
entity_id: '{{ zone_toggled }}'
OK, the persistent notification won’t get the correct details because it’s not in the script, what happens if you create the persistent notification as the first item in the script sequence?
I moved the notification and now I am making progress.
I hadn’t realised that the variables didn’t actually exist in the automation.
I was trying to see what I was passing rather than what I was being passed.