Lights on when arriving home then off after x minutes

Finally diving into automations after using HA for the past year.
I’ve seen lots of examples of people using automated lights on when arriving home using Motion detection but for the life of me I’ve searched and searched and can’t find anyone using something similar for Presence detection.

I’ve successfully got my garage lights coming on when arriving home but I just can’t figure out the rest of the code to have them turn off automatically after x number of minutes

What I have so far in automations.yaml

  alias: 'Arriving Home '
  trigger:
    platform: state
    entity_id: device_tracker.iphonexr
    from: 'not_home'
    to: 'home'
  action:
   service: light.turn_on
   entity_id: light.garage_outdoor_light_8

What am I missing? I tried delay with adding another service for light.turn.off but got an error about duplicate mapping key.

Assuming you always want that to happen after the light gets turned on with this automation then this should work:

- alias: 'Arriving Home '
  trigger:
    platform: state
    entity_id: device_tracker.iphonexr
    from: 'not_home'
    to: 'home'
  action:
   - service: light.turn_on
     entity_id: light.garage_outdoor_light_8
   - delay: '00:10:00'
   - service: light.turn_off
     entity_id: light.garage_outdoor_light_8
1 Like

Thanks so much! I was racking my brain around that for 3 days now!!!

Is it possible to configure such a away?

automation:
trigger:
platform: sun
event: sunset

  • alias: 'Arriving Home ’
    trigger:
    platform: state
    entity_id: device_tracker.iphonexr
    from: ‘not_home’
    to: ‘home’
    action:
  • service: light.turn_on
    entity_id: light.garage_outdoor_light_8
  • delay: ‘00:10:00’
  • service: light.turn_off
    entity_id: light.garage_outdoor_light_8

we can’t answer that because you didn’t format your code to display properly.

condition:
   condition: sun
   after: sunset
- alias: 'Arriving Home '
   trigger:
    platform: state
    entity_id: device_tracker.iphonetaffa
    from: 'not_home'
    to: 'home'
  action:
   - service: light.turn_on
     entity_id: light.garage_outdoor_light_8
   - delay: '00:4:00'
   - service: light.turn_off
     entity_id: light.garage_outdoor_light_8

Hope this is better, excuse me I’m newbie

- alias: arriving home
  trigger:
    platform: state
    entity_id: device_tracker.iphonetaffa
    to: home
  condition:
    condition: sun
    after: sunset
  action:
    - service: light.turn_on
      entity_id: light.garage_outdoor_light_8
    - delay: '00:4:00'
    - service: light.turn_off
      entity_id: light.garage_outdoor_light_8

try this…

No, sorry, it does not lit the light. I checked well entities but nothing

Hi tried usuccessful the following:

- alias: TEST

  trigger:

    platform: state

    entity_id:  device_tracker.iphone_raffaele_6s

    from: 'not_home'

    to: 'home'

  condition:

    condition: sun

    after: sunset

  action:

  - service: light.turn_on

    entity_id: switch.shelly_shsw_25_c4ce78_1

  - delay: 00:04:00

  - service: light.turn_off

    entity_id: switch.shelly_shsw_25_c4ce78_1

You are trying to control switches not lights.

Change the service lines to switch.turn_on and switch.turn_off instead of light.turn…

You right. Thank you very much