Condition template with trigger.entity_id doesn't work

I have an automation, which is triggered when any of two sensors changes his state.
In the action-part I want to distinguish between the triggering sensor has no value (empty string) or has some value (string).
To avoid some nested and / or conditions I want to use the trigger.entity_id:

action:
  - if:
      - condition: template
        value_template: "{{ is_state('trigger.entity_id ', '') }}"
    then:

But this doesn’t work! Then automation executes always the else-path, even when the value of the triggering sensor is empty.

When I use the entity_id of one of the sensors (e.g. sensor.ccu3_sv_gong_eg_kanalaktion) instead of trigger.entity_id, then it will work (for this sensor). So the syntax seams to be ok.

But why doesn’t it work with trigger.entity_id?

Here is the complete automation:

alias: hm_Gong Kanalaktion v2
description: ""
trigger:
  - platform: state
    id: a68c7f8074115ec59c7d830f29f4fdad
    entity_id:
      - sensor.ccu3_sv_gong_eg_kanalaktion
    to: null
  - platform: state
    id: 635c14ed311cb35e791f4b91d3114ac3
    entity_id:
      - sensor.ccu3_sv_gong_og_kanalaktion
    to: null
condition: []
action:
  - if:
      - condition: template
        value_template: "{{ is_state('trigger.entity_id ', '') }}"
    then:
      - service: homematicip_local.set_device_value
        data:
          device_id: "{{ trigger.id }}"
          channel: 2
          parameter: STATE
          value_type: boolean
          value: false
      - service: homematicip_local.set_device_value
        data:
          device_id: "{{ trigger.id }}"
          channel: 1
          parameter: STATE
          value: false
          value_type: boolean
    else:
      - service: homematicip_local.set_device_value
        data:
          device_id: "{{ trigger.id }}"
          channel: 2
          parameter: SUBMIT
          value: "{{ trigger.to_state.state }}"
          value_type: string
      - service: homematicip_local.set_device_value
        data:
          device_id: "{{ trigger.id }}"
          channel: 1
          parameter: STATE
          value: true
          value_type: boolean
mode: queued

Have you already tried to: '' ?

Try this

value_template: "{{ is_state(trigger.entity_id, '') }}"

You quoted your trigger variable, which turned it into the literal string “trigger.entity_id” instead of what that variable contains

Or maybe use this if you want the unknown state as well:

value_template: "{{ not has_value(trigger.entity_id) }}"
2 Likes

Thanks. The quoting was the problem.