Hey team! We have a 9 month old. I have a “sleeping” script that triggers at 7 pm every day. This turns a bunch of lights off and other light automations use it to not turn on large lights if the boolean is set to true.
Last night we went on a date night and there was a babysitter at home. We got home at 7:15 PM, but the house went into sleep mode at 7 pm as usual and the babysitter had trouble seeing in the dark.
Question is - what do we think is the best way for this script to trigger at 7 pm but then wait for us to be home for a few minutes?
Using “wait_for_template” is easy enough to say that group.family is home, but that means as soon as we pull in the driveway the house would turn sleeping on. I would prefer it 10-15 minutes after we get home so that the babysitter is likely gone.
I’ve hacked this up, as I already have booleans tracking whether my wife and I arrived home recently (last 10 minutes) that does other stuff, but, there’s gotta be a better way.
wait_for_trigger would be ideal as I could use the “for” attribute in the trigger saying “for : 00:10:00”, but that wouldn’t work if we were already home (never left) as the trigger’s “to: home” wouldn’t ever fire.
Thanks!!
Matt
automation:
- id: initiate_sleep
alias: "[Sleep] Initiate Sleep"
mode: single
trigger:
- platform: time
at: input_datetime.sleep_time
condition:
- condition: state
entity_id: "input_boolean.sleeping"
state: "off"
action:
- service: script.initiate_sleep_script
script:
initiate_sleep_script:
alias: "[Sleep] Initiate sleep script"
sequence:
- wait_template: "{{ is_state('group.family', 'home') }}"
timeout: "01:30:00"
- delay: "00:00:05"
- wait_template: "{{ is_state('input_boolean.matt_arrived_recently', 'off') and is_state('input_boolean.serena_arrived_recently', 'off') }}"
timeout: "00:30:00"
- service: input_boolean.turn_on
entity_id: input_boolean.sleeping