Last detected and time operations

Hi,

i wanted HA turn off a device if not activity recorded for certain time, for example turn off a light if no presence detected in 30 minutes, how you guys would implement that?

also is there any way to have time math operations??

thanks

Hi,
Like this:
First one Automation:

- id: '1111114794106'
  alias: MotionPir1 Flood Light
  trigger:
  - entity_id: binary_sensor.motionpir1_sensor
    platform: state
    to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.timed_ztick

then two scripts in scripts.yaml:

  timed_ztick:
    alias: "Turn on and set timer"
    sequence:
      # Cancel any old timers 
      - service: script.turn_off
        data: 
           entity_id: script.ztick_off
      - service: switch.turn_on
        data:
          entity_id: switch.ztick_switch
      # Set new timer 
      - service: script.turn_on
        data:
          entity_id: script.ztick_off
  ztick_off:
    alias: "Turn off after 30 minutes"
    sequence:
      - delay:
          minutes: 30
      - service: switch.turn_off
        data:
          entity_id: switch.ztick_switch
1 Like

Holy Molly, that’s awesome, i’ll give it a try and let you know how that works, thank you so much