Why is this automation not firing a trigger?

Below automation should trigger this trigger (I executed it manually):

  - platform: template
    value_template: '{{ states[''sensor.entity_offline_zigbee''].state | int > 0 }}'
    id: zigbee_offline

because value of this sensor is equal 1 (checked in the developer tools in the template section). But it going to the default option:

Automation:

alias: '[00] input_select.mobile_2_info - Update'
description: ''
trigger:
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_tuya''].state | int > 0 }}'
    id: tuya_offline
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_sensor''].state | int > 0 }}'
    id: sensor_offline
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_zigbee''].state | int > 0 }}'
    id: zigbee_offline
  - platform: state
    entity_id: timer.mobile_2_zuza_turn_off_30
    from: idle
    to: active
    id: zuza_turn_off_on
  - platform: state
    entity_id: timer.mobile_2_zuza_turn_off_30
    from: active
    to: idle
    id: zuza_turn_off_off
  - platform: state
    entity_id: input_boolean.mobile_2_roomba
    from: 'off'
    to: 'on'
    id: romba_on
  - platform: state
    entity_id: input_boolean.mobile_2_roomba
    from: 'on'
    to: 'off'
    id: roomba_off
  - platform: state
    entity_id: timer.mobile_2_security_turn_on
    to: active
    from: idle
    id: security_timer_active
  - platform: state
    entity_id: timer.mobile_2_security_turn_on
    from: active
    to: idle
    id: security_timer_idle
  - platform: state
    entity_id: input_boolean.mobile_2_security
    from: 'off'
    to: 'on'
    id: security_on
  - platform: state
    entity_id: input_boolean.mobile_2_security
    from: 'on'
    to: 'off'
    id: security_off
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_tuya''].state | int == 0 }}'
    id: tuya_online
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_sensor''].state | int == 0 }}'
    id: sensor_online
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_zigbee''].state | int == 0 }}'
    id: zigbee_online
  - platform: template
    value_template: '{{ states[''input_select.mobile_2_info''].state | int == 0 }}'
    id: mobile_2_info_0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: security_on
        sequence:
          - service: input_select.select_option
            data:
              option: '5'
            target:
              entity_id: input_select.mobile_2_info
      - conditions:
          - condition: trigger
            id: security_timer_active
        sequence:
          - service: input_select.select_option
            data:
              option: '4'
            target:
              entity_id: input_select.mobile_2_info
      - conditions:
          - condition: trigger
            id: zuza_turn_off_on
        sequence:
          - service: input_select.select_option
            data:
              option: '2'
            target:
              entity_id: input_select.mobile_2_info
      - conditions:
          - condition: trigger
            id: romba_on
        sequence:
          - service: input_select.select_option
            data:
              option: '3'
            target:
              entity_id: input_select.mobile_2_info
      - conditions:
          - condition: trigger
            id: tuya_offline
        sequence:
          - service: input_select.select_option
            data:
              option: '1'
            target:
              entity_id: input_select.mobile_2_info
          - service: telegram_bot.send_message
            data:
              message: Tuya devices are offline.
              target: 000
      - conditions:
          - condition: trigger
            id: sensor_offline
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mobile_2_info
            data:
              option: '1'
          - service: telegram_bot.send_message
            data:
              target: 000
              message: Motion sensors are offline.
      - conditions:
          - condition: trigger
            id: zigbee_offline
        sequence:
          - service: input_select.select_option
            target:
              entity_id: input_select.mobile_2_info
            data:
              option: '1'
          - service: telegram_bot.send_message
            data:
              target: 000
              message: Zigbee devices are offline.
    default:
      - service: input_select.select_option
        data:
          option: '0'
        target:
          entity_id: input_select.mobile_2_info
mode: single

Any idea why it doesn’t triggers the specific trigger?

The Template Trigger you created is invalid. If you tested the automation by executing Run Actions or by using automation.trigger then all you have confirmed is that the action works (because they don’t actually exercise the trigger). For more information, refer to Troubleshooting Automations.

Change the template to this:

    value_template: '{{ states(''sensor.entity_offline_tuya'') | int(-1) > 0 }}'

Thank you for reply, the order of the triggers is important? Means the triggers will be validated in the order or the first trigger which will meet the criterias will trigger automation?

Multiple triggers are logically ORed so whichever trigger meets its criteria will serve to trigger the automation.

1 Like

It makes sense now, the templates for the triggers where not logically excluded. Thank you for help.

@123 when this trigger will be triggered?
How often this template condition will be checked?

alias: '[00] input_select.mobile_2_info - Update'
description: ''
trigger:
  - platform: template
    value_template: '{{ states[''sensor.entity_offline_tuya''].state | int > 0 }}'
    id: tuya_offline

The template is evaluated every time the value of sensor.entity_offline_tuya changes.

I don’t know where you learned to use this convention to get an entity’s state value:

states[''sensor.entity_offline_tuya''].state

but you should avoid it. Review the warning here.

Use this convention:

states(''sensor.entity_offline_tuya'')

In addition, you should provide the int filter with a default value.

    value_template: '{{ states(''sensor.entity_offline_tuya'') | int(0) > 0 }}'
1 Like

Thank you for the clarification, I will update my automations to adjust to this format.