I’m trying to setup a few basic automations in a new hassio install. I’ve created an automation to turn on a few flood lights with a motion sensor. Set the duration for 15:00. Do I still need to create an automation to turn the lights off?
Can’t possibly be all that “new” because it’s no longer called “hassio”. Hasn’t been called that for many months when it was renamed to Home Assistant OS. Check the docs; there’s no usage of “hassio”.
Yes.
From what I can see in the screenshot, you have created a trigger where motion must be detected for a minimum of 15 minutes before it triggers (or at least that’s what I assume it does; I don’t normally use the Automation Editor; the option is actually called for
as opposed to the way the Automation Editor refers to it as ‘Duration’). The condition requires that this 15-minute interval of motion must occur prior to sunrise to permit the automation to execute the action (which is not visible in the screenshot). I assume the action turns on a light. It will remain that way until something else turns it off.
For future reference, it’s easier to share an automation in YAML format (text format) as opposed to a screenshot. If you’re using version 0.117, there’s a new feature in the Automation Editor that allows you to flip to YAML mode (and back). Once in text mode, you can easily copy/paste it into a forum post.
Thanks. Found the YAMl.
alias: motion_activation
description: ''
trigger:
- type: motion
platform: device
device_id: 24157696796a0d0045508adff42ff641
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
domain: binary_sensor
for:
hours: 0
minutes: 15
seconds: 0
condition:
- condition: sun
before: sunrise
after: sunset
action:
- type: turn_on
device_id: 294247b81aa20bae5e0a25eaef4c5c85
entity_id: switch.togglelinc_on_off_12_13_48
domain: switch
- type: turn_on
device_id: 801b9d5a17f211eb9b57af25daa05fcf
entity_id: light.driveway_light
domain: light
mode: single
My goal is to turn on these two devices when any motion is detected (no time limit) and turn them back off after a 15 minute delay.
I think maybe I’ve figured this out. I created two automations.
The first will turn lights on-
alias: motion_activation_lights_on
description: ''
trigger:
- type: motion
platform: device
device_id: 24157696796a0d0045508adff42ff641
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition:
- condition: sun
before: sunrise
after: sunset
action:
- type: turn_on
device_id: 294247b81aa20bae5e0a25eaef4c5c85
entity_id: switch.togglelinc_on_off_12_13_48
domain: switch
- type: turn_on
device_id: 801b9d5a17f211eb9b57af25daa05fcf
entity_id: light.driveway_light
domain: light
mode: single
The second will turn them off-
alias: motion_activation_lights_off
description: ''
trigger:
- type: no_motion
platform: device
device_id: 24157696796a0d0045508adff42ff641
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
domain: binary_sensor
for:
hours: 0
minutes: 15
seconds: 0
condition: []
action:
- type: turn_off
device_id: 294247b81aa20bae5e0a25eaef4c5c85
entity_id: switch.togglelinc_on_off_12_13_48
domain: switch
- type: turn_off
device_id: 801b9d5a17f211eb9b57af25daa05fcf
entity_id: light.driveway_light
domain: light
mode: single
I removed the condition in the second automation so that the lights will turn off even if it is after sunrise. Not sure if that was necessary or if maybe there’s a better way to do this???
At the risk of “starting something”, that’s not entirely correct.
hassio is still used in the docs or at least in HA itself in many places. It sure would be easier to convey the new paradigm if those instances would be wiped away. Well, except for the thousands of forum posts and potentially millions of internet references to hassio (including the two more I just created ). Those will never go away.
Must have something wrong. It doesn’t work.
OK, show me just 3 places (in the user docs).
Which part? Turning the lights on or off? Or both?
Wouldn’t turn on by activating the motion sensor. Not sure about the “off”. Is there an automation log I can check?
Try this:
alias: motion_activation_lights_on
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'on'
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
- service: homeassistant.turn_on
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
mode: single
alias: motion_activation_lights_off
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'off'
for: '00:15:00'
action:
- service: homeassistant.turn_off
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
mode: single
EDIT
Corrected the first automation’s condition. The test cannot be performed as a single sunrise/sunset condition but as two separate, logically ORed conditions.
The condition will always return false as it can never be both before sunrise (midnight to say 6am) AND after sunset (say 6pm and midnight) at the same time.
What condition should I set to only have the lights turn on at night?
Oops! You’re right! I had even skimmed Sunrise-Sunset Condition, and failed to notice that it explicitly cites this example as NOT how to implement a “when it’s dark” condition. You have to separate it as two, logically ORed conditions. I’ll use the excuse that “It was late …”
The correct way, clearly shown in the documentation, is like this:
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
I’ll correct my previous example.
See my amended example above. As per the example in the documentation, to check if the current time is between sunset and sunrise, you have to use separate Sunrise-Sunset Conditions and logically OR the two conditions.
Or wrap it all into one automation like this:
alias: motion_activation_lights_on
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'on'
condition:
- condition: or
conditions:
- after: sunset
after_offset: -00:30:00
condition: sun
- before: sunrise
before_offset: 00:30:00
condition: sun
action:
- service: homeassistant.turn_on
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
- wait_template: '{{ is_state(''binary_sensor.motion_sensor_ii_54_57_5b_motion'', ''off'') }}'
timeout: 00:15:00
- service: homeassistant.turn_off
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
mode: restart
I have converted all my light automations to a single one like this. The offset is useful as it is normally still dark before sunet and after dawn, the mode: restart ensures that the automation is restarted if motion is detected within the 15 minute timeout period.
Are you saying the timeout
behavior in this:
- wait_template: '{{ is_state(''binary_sensor.motion_sensor_ii_54_57_5b_motion'', ''off'') }}'
timeout: 00:15:00
is identical to the behavior of the for
in this?
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'off'
for: '00:15:00'
It’s my understanding that timeout
and for
serve different purposes.
-
The
timeout
ensureswait_template
doesn’t wait forever for the template to evaluate totrue
. It represents the maximum waiting time before it ceases waiting and proceeds executing the balance of the action. It will also cease waiting the moment the template evaluates totrue
which can easily be less than thetimeout
value. Wait Timeout -
The
for
specifies how long the state must remain unchanged before the trigger occurs. Holding a state
I believe we would need to use wait_for_trigger to duplicate the desired behavior where the lights are turned off only after there’s no motion for 15 minutes:
alias: motion_activation_lights_on
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'on'
condition:
- condition: or
conditions:
- after: sunset
after_offset: -00:30:00
condition: sun
- before: sunrise
before_offset: 00:30:00
condition: sun
action:
- service: homeassistant.turn_on
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
to: 'off'
for: '00:15:00'
- service: homeassistant.turn_off
entity_id: switch.togglelinc_on_off_12_13_48, light.driveway_light
mode: restart
As a refinement, I suggest adding another State Condition that checks if the switch and light are currently off. This is to prevent needlessly turning them on if they are already on. This is a plausible possibility because a motion sensor can toggle frequently while people are milling around.
Ah, you have spotted a vital omission on my part - I have a ‘delay: 00:15:00’ before the ‘wait_template’ in my config. This has been working great on all my automated lights for many weeks however I think your suggestion using a ‘wait_for_trigger’ is perhaps a little more elegant so I will give that a try.
Use a state condition with the sun as the entity, and below_horizon as the state. If you look under dev tools> states, you can see for yourself that the sun’s state is either above or below horizon.
You could also just make your second automation at wait for trigger in the first automation. That way it is all in one place, and if you turn on your lights for some other reason they won’t go off after 15 minutes of no motion (which may or may not be desirable, only you know ).
Edit: someone beat me to the punch
Still not the same as what a for
does.
A delay simply waits for a fixed time to pass. There may still be motion in the 14th minute of the 15-minute delay period. In contrast, for
requires 15 continuous minutes of no motion before it triggers (given the way it is used in the first example).
I think it probably achieves the same thing because having ‘mode: restart’ restarts the automation whenever motion is susequently detected. That means that you can only get past the delay when no motion has been detected for 15 minutes.
I saw the state condition and added it to the yaml-
alias: motion_activation_lights_on
description: ''
trigger:
- type: motion
platform: device
device_id: 24157696796a0d0045508adff42ff641
entity_id: binary_sensor.motion_sensor_ii_54_57_5b_motion
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- type: turn_on
device_id: 294247b81aa20bae5e0a25eaef4c5c85
entity_id: switch.togglelinc_on_off_12_13_48
domain: switch
- type: turn_on
device_id: 801b9d5a17f211eb9b57af25daa05fcf
entity_id: light.driveway_light
domain: light
mode: single
I’ve actually got two motion sensors at slightly different location s on my driveway and wanted to use both as triggers so I created a group-
group:
driveway:
name: driveway motion detection group
entities:
- binary_sensor.driveway_motion
- binary_sensor.motion_sensor_ii_54_57_5b_motion
I can’t figure out how to use this group as a trigger though? I don’t see it listed as a device or entity and I don’t see an option for “group” in the trigger type.