Motion is the event that will triggers the automation, so you’ll create an automation with a state trigger for the motion sensor. You only want the automation to fire when it’s dark, so you’ll have to add a state condition (maybe a numeric_state condition) to the automation. The action of the trigger should be to turn on the switch, have a ten minute delay, and then turn off the switch.
With that information you should be able to find the necessary info to create the automation in the documentation. Take a stab at it! If you get stuck one of us will be happy to help.
first thing i tried is trying to put everything into automations.yaml file.
nothing worked. the fact that original automations.yaml file has this []
confused me.
So, i tried the next best thing, add "automation:" to my configuration.yaml file.
Logically, it is simple. only thing that i am not sure of is how to “make the light only turn on for 10 minutes and automatically turn off” So, I leaving that part of logic out first… trying to make sure motion sensor triggers the switch.
(i am using zooz 4-in-1 sensor, the motion part has two values i can leverage, one of the value is simply “burglar” sensor which raise value from zero to 8 when it detect motion)
and I got stuck immediately. The error message is very cryptic:
mapping values are not allowed here
in this line: trigger:
I have no idea what went wrong. Any idea?
thanks in advance
If i just want the light to be turn on for 10 minutes when motion is detected, how to do that?
I was hoping that the same trigger can just initiate 1. turn on the light, 2. delay for 10 minutes, 3. turn off the light. This is something I came up with, it passed all the syntax check:
That should work, I’ve done similar - though I now use multiple automations, as in the cookbook link, since otherwise it’ll turn it off after 10 minutes, regardless.
the zwave switch I got is pleasantly surprised in many ways (Hank so01) it actually has voltage and current measurement), but one thing I absolutely hate is that apparently it has no separation between “on” and “off.”
So, service: switch.turn_on
and service: switch.turn_off
are exact same call.
This complicated my script because I can’t simply call switch.turn_off after 10 minutes. I need to add more conditions
the original logic is as follows:
if motion detected
if dark
turn on light
delay 10 minute
turn off light
the actual code, which almost worked, is following.
Note that lack of if/then statement make the code a lot more complicated than it should be:
since this silly switch’s “on” and “off” are the same, I need to determine rather the light is already on or not (by looking at the power which the switch is consumed… a 4-watts light bulb).
if motion detected
if dark
if light is off
turn on light
delay 10 minutes
turn off light
if light is already on
delay 10 minutes
turn off light
but apparently, i can’t just embed “condition” inside “action.”
here is the code i wrote which didn’t pass the syntax test:
I’m just looking at this quickly, but you CAN add conditions in the middle of scripts. So instead have your automation call a script you create called like script.ten_minute_light that does what you want.
as long as there is only ONE action, I understand the structure completely.
I start confused when I need perform different actions based upon conditions.
can home automation script support such basic logical scenario?
trigger
condition
action:
condition1
action1
condition2
action2
based upon your advice, I will need two scripts:
First script is called “turn on light for 10 minutes.yaml”
Second script is called “turn off light after 10 minutes.yaml”
and depend upon rather light is already on or not, I need to perform two distinct actions, and I don’t know how to do that without breaking it up the automation script into completely separate script