Not all actions of an automation are executed

Hi,

I’ve created an automation that gets triggered by MQTT.
I added two actions to this automation.
The value that needs to be set to the input number is calculated by a template.
The problem is that always only the first action triggers.
I don’t know if this is important but when the seconds action needs to be triggered the if condition in the first value is false.

here is my automation:

alias: Audio volume update
  description: ''
  trigger:
  - platform: mqtt
    topic: Audio/Status
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: "{% if trigger.payload[5:-1].split(',') [0] | int  == 3 %}\n  {{ trigger.payload[5:-1].split(',')\
        \ [1] | int }}\n{% endif %}"
    entity_id: input_number.zone3_volume
  - service: input_number.set_value
    data:
      value: "{% if trigger.payload[5:-1].split(',') [0] | int  == 6 %}\n  {{ trigger.payload[5:-1].split(',')\
        \ [1] | int }}\n{% endif %}"
    entity_id: input_number.zone6_volume
  mode: single

What could be the problem here?

Check Configuration > Logs for error messages.

What do you think happens when the comparison, performed in the first template, is not equal to 3?

  - service: input_number.set_value
    data:
      value: >
        {% if trigger.payload[5:-1].split(',') [0] | int  == 3 %}
          {{ trigger.payload[5:-1].split(',') [1] | int }}
        {% endif %}
    entity_id: input_number.zone3_volume

The answer is that the template reports nothing and nothing is not a valid value. That explains why the second action is never performed when the first action is false as you noticed when you wrote this:

Long story short, if you create a template to supply a value, then it must supply one.

Yes that’s stupid of me, there is indeed no value when the if condition is false :roll_eyes:.
I now included the “else” part that is just putting the current (known) value of the “input_number” and it is working fine!
Thank you!

1 Like