Template sensor automation not working

This template sensor:

  - platform: template
sensors:
  alarm_status:
    friendly_name: "Triggered Alarms"
    value_template: >-
      {% if is_state('binary_sensor.master_motion', 'on') %}
        Bedroom Motion!
      {% else %}
        clear
      {% endif %}
      {% if is_state('binary_sensor.office_motion', 'on') %}
        Office Motion!
      {% else %}
        clear
      {% endif %}

Generates

sensor.alarm_status = clear clear

or

= Bedroom Motion! Office Motion!

but I can’t get this automation to fire:

- alias: Security - Motion Alarm

  trigger:
    - platform: state
      entity_id: sensor.alarm_status
      from: 'clear'
      to: 'Bedroom Motion!'
    - platform: state
      entity_id: sensor.alarm_status
      from: 'clear'
      to: 'Office Motion!'

  condition:
    - condition: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'armed_away'

  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.ha_alarm

If I change the template sensor to just one entity, then it works fine. Does that mean the trigger doesn’t understand the state from: 'clear' since the state of the sensor.alarm_status is actually clear clear?

I hope it makes sense. Thanks!

You need two separate sensors for this.

1 Like

There are already two suitable sensors so why not use those instead of the template sensor to trigger:

- alias: Security - Motion Alarm
  trigger:
    - platform: state
      entity_id: binary_sensor.master_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.office_motion
      to: 'on'
1 Like

That’s what I thought too.

@dvilo I was working on a automationthat was going to include which entity was triggered in a notification but I just ended up using {{ trigger.to_state.attributes.friendly_name }}.

Thanks for your help!