Timer to turn off light and switch help please

Hello

I have a script that turns on the hallway light and outside front door light when my wife arrives home after a certain time. It triggered last night accidentally (gps hiccup I think) but I’d like to add a timer to it so it goes off after 10 minutes. What do I need to add to this please?

alias: Hallway on when Helen arrives home
hide_entity: False
trigger:
  - platform: state
    entity_id: device_tracker.helen
    from: 'not_home'
    to: 'home'

condition:
  - condition: numeric_state
    entity_id: sensor.solar_angle
    below: -8.0

action:
   - service: light.turn_on
     entity_id: light.hallway
     data:
       brightness: 180
   - service: switch.turn_on
     entity_id: switch.front_door_switch_15_0

Cheers
Mark

Turn on lights with a resettable off timer

yeah thanks, I do that already for motion in kitchen/bathroom etc but was wanting to know if there is a way of doing it in 1 automation using a device tracker state?

You could just add more actions, a delay followed by turning the light off.

yeah I tried that before and I couldn’t get it to work

I added the following but epic fail :frowning:

   - service: light.turn_off
     entity_id: light.hallway
     for:
        minutes: 10
   - service: switch.turn_off
     entity_id: switch.front_door_switch_15_0
     for:
        minutes: 10

Sorry, I meant a literal delay:

action:
  - service: light.turn_on
    entity_id: light.hallway
    data:
      brightness: 180
  - service: switch.turn_on
    entity_id: switch.front_door_switch_15_0
  - delay: '00:10:00'
  - service: switch.turn_off
    entity_id: switch.front_door_switch_15_0

Perfect! thank you so much…

is there a way I could call a script that would check a condition, say Time before 10pm, so do not turn off the outside light (as it auto comes on after sunset and off at 10pm) but turn off the hallway light?

I don’t want my wife to come home at 9pm and it then turns off the outside light before 10pm

I am getting myself all confused as to the best way to do it? any thoughts please?

Cheers
Mark

IMO, it would be simpler to:

  1. Turn on the outside light at sunset
    https://home-assistant.io/cookbook/automation_sun/
  2. Then apply your config to turn it off.

Not as such, without getting into AppDaemon.

I’d instead use the approach Coolie1101 is suggesting. Turn it on automatically and then work out the conditions that would result in it being turned off. For example, if you’re using OwnTracks or another tracker that will give you either time or distance to home, then you could do something like:

  • Turn off at 10:00 if everybody is home
  • Turn off at 10:00 if you aren’t home, and you’re more than 20 minutes from home
  • Turn off at 10:00 if your wife isn’t home, and she’s more than 20 minutes from home
  • After 10:00, turn on when whoever is away is within 10 minutes of home
  • After 10:00, turn off 5 minutes after somebody comes home

Each of those would be a separate automation, though with care you might be able to merge the second and third, and maybe all the first three.

Ah thanks. I did install appdaemon ages ago and didnt do much with it… maybe an idea, if not i could spilt like you say. Cheers Mark

you got me thinking, it would be easier if I kept the turn on automatically at sunset and off again at 22:00 then had a condition where if the light is OFF and Solar angle is say -8 as it is 100% after 22:00 and light is already off, then using a distance trigger via phones/gpslogger to turn on etc etc

will post code once I work it out :smiley:
but thanks, gave me something to think about, as I was stuck :slight_smile: