Save the last status change of a motion detector and calculate based on that

I think you’re overthinking it. If you’re only triggering updates based on changing “to on”, you can just use the {{ now() }} to record the time of the last trigger.

So I think the below code should do what you want:

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.bewegungsmelder_schreibtisch
        to: 'off'
    sensor:
      - name: "Bla bla bla"
        state: "{{ now() }}"
        device_class: timestamp
2 Likes