Sensor trigger last_changed

HI,

I use this in most of my presence automations, and it works just fine, without using the sensor.time in the entity_id section of the trigger, or the value_template:

  - condition: template
    value_template: >
      {{ (now() - trigger.from_state.last_changed | default(0)).total_seconds() > 
                                        states('input_number.presence_timer')|int }}

triggering states are like this:

  - alias: Presence Tracking
    id: 'Presence Tracking'
    trigger:
      platform: state
      entity_id:
        - group.person1
        - group.person2
        - group.person3
        - group.person4

whenever the group changes state and it is longer than the time I have set the timer to check, it evaluates true, and fires the action.

Surely the poster could replace the state with the sensor.temperature and the value_template use 30*60?
Unless he wanted it to fire, even when no last_change has happened of course, in which case this template wouldn’t suffice.
This only fires if there has been a minimum of time between the 2 checked times, and not if anything happens sooner.

1 Like