Unable to create binary sensor based on trigger with template

Dear all,

I want to create a binary sensor using the template integration. The state of this binary sensor should be changed to true when the value of a second sensor, a counter, changes. See below for what I have set in my configuration.yaml file (you can ignore the first two sensor entries, I include them for the sake of completeness). Although I get no errors anywhere, neither passage_sensor_right_left nor passage_sensor_left_right is created.

Any suggestions?

Thanks in advance.

template:
  - sensor:
      - name: "Living area Humidity"
        unit_of_measurement: "%"
        state: >
          {% set h1 = states('sensor.thermostat_humidity') | float %}
          {% set h2 = states('sensor.netatmo_indoor_module_humidity') | float %}
          {{ ((h1 + h2) / 2) }}
        unique_id: living_area_humidity
        icon: "mdi:water-percent"
  - sensor:
      - name: "Living area Temperature"
        unit_of_measurement: "°C"
        state: >
          {% set m1 = states('sensor.thermostat_temperature') | float %}
          {% set m2 = states('sensor.netatmo_indoor_module_temperature') | float %}
          {{ ((m1 + m2) / 2) }}
        unique_id: living_area_temperature
        icon: "mdi:thermometer"
  - trigger:
      - platform: state
        entity_id: sensor.passage_sensor_passage_counter_value_ch3
    binary_sensor:
      - name: "Passage Dining Kitchen"
        state: true
        auto_off: 5 # s
        icon: "mdi:eye"
        unique_id: passage_sensor_left_right
  - trigger:
      - platform: state
        entity_id: sensor.passage_sensor_passage_counter_value_ch2
    binary_sensor:
      - name: "Passage Kitchen Dining"
        state: true
        auto_off: 5 # s
        icon: "mdi:eye"
        unique_id: passage_sensor_right_left

Replace this:

state: true

with this:

state: '{{ true }}'

Thanks, unfortunately that doesn’t work for me.

I tested the same configuration except with a sensor entity that exists on my system.

When the monitored sensor entity changes state, the Trigger-Based Binary Template Sensor changes to on.

Five seconds later, the Trigger-Based Binary Template Sensor changes to off.

Ok, that is interesting, maybe then I am confused by how the settings for a template sensor work. I thought that the “non-friendly” name of the identity would be the one I set in unique_id so passage_sensor_left_right and passage_sensor_right_left. Or does HA create a name based on name, meaning Passage Kitchen Dining becomes passage_kitchen_dining?

If name is provided then, yes, that’s what it uses to create the entity_id.