Help with a service call with data please

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 %}

Going to need to see…

  • the full automation
  • the contents of script.check_zone_connection_allowed
  • what you’re seeing when you activate this (error message, any results, any kind of feedback whatsoever)

Yes, sorry…
In a nutshell I have 4 Booleans,

zone3_connected
zone4_connected
zone5_connected
zone6_connected

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:

- alias: hide_show_zone
  trigger:
    - platform: state
      entity_id: input_boolean.zone3_connected
    - platform: state
      entity_id: input_boolean.zone4_connected
    - platform: state
      entity_id: input_boolean.zone5_connected
    - platform: state
      entity_id: input_boolean.zone6_connected
  action:
    - 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 %}
    - service: persistent_notification.create
      data_template:
        message: |
          trigger.entity_id -{{ trigger.entity_id }}
          zone_toggled -{{ zone_toggled }}
          previous_zone -{{ previous_zone }}
        title: "*** INFORMATION ***"
    - service: script.valid_zone_configuration

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.

image

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?

Thank you!!!

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.

Now I just need to get it working.
Thanks again.

1 Like