Template sensor to tell me how long a door remained open for the last time

I think i have an elegant solution now:

  - trigger:
      - platform: state
        entity_id: binary_sensor.lumi_lumi_sensor_magnet_02012603_on_off
        from: 'on'
        to: 'off'
    sensor:
      - name: door last opened2
        state: "{{ (trigger.to_state.last_updated | as_timestamp - trigger.from_state.last_updated | as_timestamp) | int }}"

i’d love to use trigger.for.seconds instead, but it returns null, so i have to do the timedelta manually

1 Like