[solved] Template - Turning an trigger into a binary sensor - Not work

I try make binary sensor from trigger, but binary sensor not work:
Example in Documentation: Template - Home Assistant
Code:

template:
  - trigger:
      - platform: state
        entity_id: sensor.remote_event_a4ek00_button
  - binary_sensor:
      - name: "Yeelight Childroom Button Click"
        icon: mdi:gesture-tap-button
        auto_off: 1
        state: "true"

  - trigger:
      - platform: state
        entity_id: binary_sensor.yeelight_childroom_button_click
  - sensor:
      - name: "Yeelight Childroom Button"
        icon: mdi:gesture-double-tap
        state: >
          {%- if states('binary_sensor.yeelight_childroom_button_click') -%}
            {{ states('sensor.remote_event_a4ek00_button_click_type') }}
          {%- else -%}
            no press
          {%- endif -%}

Result:
image

image

after 1 minutes binary sensor is On :frowning:

Can you explain what it is you are trying to do?

Check the docs again. There is no dash in front of sensor: or binary_sensor: only in front of trigger:.

You want to make a list of triggered sensors, not a list of triggers and sensors.

template:
  - trigger:
      - platform: state
        entity_id: sensor.remote_event_a4ek00_button
    binary_sensor:
      - name: "Yeelight Childroom Button Click"
        icon: mdi:gesture-tap-button
        auto_off: 1
        state: "true"

  - trigger:
      - platform: state
        entity_id: binary_sensor.yeelight_childroom_button_click
    sensor:
      - name: "Yeelight Childroom Button"
        icon: mdi:gesture-double-tap
        state: >
          {%- if states('binary_sensor.yeelight_childroom_button_click') -%}
            {{ states('sensor.remote_event_a4ek00_button_click_type') }}
          {%- else -%}
            no press
          {%- endif -%}

If you want to add some state based sensors as well, then you can add the dash in front of sensor: or binary_sensor: Then your list will contain triggered sensors, and sensors.

template:

# triggered sensors

  - trigger:
      - platform: state
        entity_id: sensor.remote_event_a4ek00_button
    binary_sensor:
      - name: "Yeelight Childroom Button Click"
        icon: mdi:gesture-tap-button
        auto_off: 1
        state: "true"

  - trigger:
      - platform: state
        entity_id: binary_sensor.yeelight_childroom_button_click
    sensor:
      - name: "Yeelight Childroom Button"
        icon: mdi:gesture-double-tap
        state: >
          {%- if states('binary_sensor.yeelight_childroom_button_click') -%}
            {{ states('sensor.remote_event_a4ek00_button_click_type') }}
          {%- else -%}
            no press
          {%- endif -%}

# state based sensors (examples)

  - sensor:
      - name: "Transmission Down Speed"
        unit_of_measurement: "kB/s"
        state: "{{ states('sensor.transmission_down_speed')|float * 1024 }}"

      - name: "Transmission Up Speed"
        unit_of_measurement: "kB/s"
        state: "{{ states('sensor.transmission_up_speed')|float * 1024 }}"

  - binary_sensor:
      - name: "Washing Machine"
        delay_off:
          minutes: 5
        state: >
          {{ states('sensor.washing_machine_power')|float > 0 }}
1 Like

I went a long way, from the sensor to the template, and then to the template trigger. So I came up with something superfluous. And there is no errors when config check. Now I removed it, I will check it. Thanks.

Automatic status change of button press status.

Thanks! All works!