My son (3), turns on his room lights every time I leave the room, which keeps him awake. I was curious if I could create a script that will automatically turn the lights off, every time he turns them on between 9PM and 8AM.
I haven’t used Home Assistant before, but I have several smart home TP-Link Kasa Smart Switches. I was thinking I could install one in his room and then write a script or something that’s run every time the light is turned on, and then check the time, and then turn it off it’s between certain hours.
I of course need a way to override this from my phone.
In a perfect world, I’d be able to trigger this via Alexa, and not based on the current time, where I can say “Alexa, lock the lights in room”, and then after he falls asleep unlock them so I can change his diaper with the lights on in the middle of the night or something.
I get the impression that would be very frustrating and will just cause junior to stand at the switch flicking it on and off until he gets the desired result, which won’t happen.
So behavior dependent I would introduce a delay so he thinks the light is turned on, gets back into bed and then the light turns off, He’ll get sick of getting up to turn it back on. Especially if the delay is somewhat random in length.
You do realize that all automations are stored in YAML format? Even the ones created using the Automation Editor.
When using the Automation Editor to create/modify an automation, you can switch from visual mode to YAML mode. What is displayed is the automation in its true form.
No but ultimately all automations and scripts are stored in YAML format. It’s far more compact to show you an automation in YAML format then to post a series of screenshots captured from the Automation Editor.
It’s also more convenient and portable. Usually you can copy-paste an automation’s YAML code from the forum directly into the Automation Editor (while in YAML mode). Switch the Automation Editor to visual mode and it will be presented in GUI format.
I apologize for my curious statement. I meant that besides writing YAML code you could use the automations feature in Home Assistant. And indeed the automations are translated into YAML.
OR - you can create an automation to turn the input_boolean OFF and turn the light OFF. You will need to find out how long on average does it takes for you to change his diaper. Below is an automation to turn it OFF after 10 minutes. Adjust the '00:10' accordingly to your needs.
alias: Turn OFF Input Boolean and Lights (Child Bedroom)
description: ''
mode: single
trigger:
- platform: state
entity_id: input_boolean.child_bedroom_light_override
to: 'on'
for: '00:10'
condition: []
action:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.child_bedroom_light_override
- service: light.turn_off
target:
entity_id: light.your_light
Note: Unfortunately, I am unfamiliar with Alexa. Therefore, I do not know how can you call a script from it. Here’s an alternative for you if you are using iOS-
I think this (or the later gradual dim) suggestion addresses a valid safety concern too should light be needed either by your son or by you entering the room.