Automation condition template based on trigger

Hello i’m trying to figure out how to template automation conditions. The conditions should be based on the automation trigger. When i check the config i don’t see any errors. However the automation doesn’t fire. Can anyone help me out with this?

- alias: Stekker bed uit wanneer iemand vertrekt in de ochtend
  trigger:
   - platform: state
     entity_id: group.glenn
     from: 'home'
     to: 'not_home'
     for:
       seconds: 30
   - platform: state
     entity_id: group.ellen
     from: 'home'
     to: 'not_home'
     for:
       seconds: 30
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: sensor.partofday
        state: 'Ochtend'
      - condition: template
        value_template: >
          {% if trigger.entity_id == 'group.glenn' %}
            is_state('switch.bed_glenn', 'On')
          {% else %}
            is_state('switch.bed_ellen', 'On')
          {% endif %}
  action:
    - service: switch.turn_off
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'group.glenn' %}
            switch.bed_glenn
          {% else %}
            switch.bed_ellen
          {% endif %}
    - service: notify.pushover
      data_template:
        message: >
          {% if trigger.entity_id == 'group.glenn' %}
            Stekker bed Glenn uitgeschakeld.
          {% else %}
            Stekker bed Glenn uitgeschakeld.
          {% endif %}

I’m looking to get this part of the automation working. When I comment this out. Everything is working fine.

      - condition: template
        value_template: >
          {% if trigger.entity_id == 'group.glenn' %}
            is_state('switch.bed_glenn', 'On')
          {% else %}
            is_state('switch.bed_ellen', 'On')
          {% endif %}
1 Like

can’t really see what’s wrong.
Maybe try and change like this to remove trailing spaces as “true” is not the same as " true "

      - condition: template
        value_template: >-
          {%- if trigger.entity_id == 'group.glenn' -%}
            is_state('switch.bed_glenn', 'On')
          {%- else -%}
            is_state('switch.bed_ellen', 'On')
          {%- endif -%}

Also conditions are “AND” by default so no need for:

  condition:
    condition: and
    conditions:

Unfortunately it’s not working…

Do I just change this?

condition:
    condition: and
    conditions:

with this

condition:

- alias: Stekker bed uit wanneer iemand vertrekt in de ochtend
  trigger:
   - platform: state
     entity_id: group.glenn
     from: 'home'
     to: 'not_home'
     for:
       seconds: 30
   - platform: state
     entity_id: group.ellen
     from: 'home'
     to: 'not_home'
     for:
       seconds: 30
  condition:
    - condition: state
      entity_id: sensor.partofday
      state: 'Ochtend'
    - condition: template
      value_template: >-
        {%- if trigger.entity_id == 'group.glenn' -%}
          {{is_state('switch.bed_glenn', 'On')}}
        {%- else -%}
          {{is_state('switch.bed_ellen', 'On')}}
        {%- endif -%}
  action:
    - service: switch.turn_off
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'group.glenn' %}
            switch.bed_glenn
          {% else %}
            switch.bed_ellen
          {% endif %}
    - service: notify.pushover
      data_template:
        message: >
          {% if trigger.entity_id == 'group.glenn' %}
            Stekker bed Glenn uitgeschakeld.
          {% else %}
            Stekker bed Glenn uitgeschakeld.
          {% endif %}
2 Likes

That’s what I have right now. Not working however.

think I’ve just fixed it in above script. You forgot the curly braces around is_state('switch.bed_glenn', 'On') so it would just output this string instead of true/false

1 Like

Nope. It’s still not working. :frowning:

Try lowercase for ‘on’.

2 Likes

This fixed it!

1 Like