State triggered binary sensor template difficulties

I feel like I am missing some fundamentals when it comes to understanding how to make a triggered sensor.

I want to create a new sensor that tracks the state of another sensor, but only updates if the state has been consistent for 10 minutes.

This is what I have (which doesn’t work):

  - trigger:
      - entity_id: binary_sensor.boiler_on
        from: "off"
        to: "on"
        for: "00:10:00"
      - entity_id: binary_sensor.boiler_on
        from: "on"
        to: "off"
        for: "00:10:00"
    binary_sensor:
      - name: boiler on sticky
        state: "{{binary_sensor.boiler_on}}"
        icon: mdi:water-boiler

Which causes an error to be thrown which states

Invalid config for 'template' at configuration.yaml, line 102: required key 'trigger' not provided

Could someone tell me what I need to do to get this to work? I can’t seem to figure out what the formatting should be for this thing… Also, if someone could point me to something that explains how to understand this, I would really like to get better at it.

Thanks!

Hello johnwdailey,

This help you any?

1 Like

I tried reading the examples on that page before I posted. I did manage to get it to work, but I’m not sure I understand why/how…

  - trigger:
      - trigger: state
        entity_id: binary_sensor.boiler_on
        from: "off"
        to: "on"
        for: "00:10:00"
      - trigger: state
        entity_id: binary_sensor.boiler_on
        from: "on"
        to: "off"
        for: "00:10:00"
    binary_sensor:
      - name: boiler on sticky
        state: "{{binary_sensor.boiler_on}}"
        icon: mdi:water-boiler

I don’t think you did… "{{binary_sensor.boiler_on}}" will not return anything useful. You need to use the states() function to get the value of the entity’s state.

It’s also possible to do what you want without triggers by using the delay_on and delay_off configuration keys.

- binary_sensor:
    - name: boiler on sticky
      state: "{{ is_state('binary_sensor.boiler_on', 'on') }}"
      icon: mdi:water-boiler
      delay_on: "00:10:00"
      delay_off: "00:10:00"
2 Likes

Thank you!

I had figured out that I didn’t get it working, only that I got it to not throw errors.

The solution you suggest is much more elegant. Thank you!

I’m gonna implement my sensor as you suggest, but for my own education, would this work?

  - trigger:
      - trigger: state
        entity_id: binary_sensor.boiler_on
        from: "off"
        to: "on"
        for: "00:10:00"
      - trigger: state
        entity_id: binary_sensor.boiler_on
        from: "on"
        to: "off"
        for: "00:10:00"
    binary_sensor:
      - name: boiler on sticky
        state: >-
          {{ states('binary_sensor.boiler_on') }}
        icon: mdi:water-boiler

Yes, or you could also use the trigger variable instead of re-querying the state:

  - trigger:
      - trigger: state
        entity_id: binary_sensor.boiler_on
        from: 
          - "on"
          - "off"
        to:  
          - "on"
          - "off"
        for: "00:10:00"
    binary_sensor:
      - name: boiler on sticky
        state: "{{ trigger.to_state.state }}"
        icon: mdi:water-boiler
1 Like

Thank you.

You have been very helpful