Hi all, new to HA - using a PI4 and got it all working, dashboard created.
Had my combi zigbee stick delivered today and play around with automations
Ive added a smartthings motion sensor and all I want to do is a simple automation
motion detected turn light on (easy can do that)
where Im stuggling is getting further things to happen.
So ideally id like the light to turn when motion is detected after sunset and until sunrise and turn off if no motion is detected say after a minute. Id be over the moon if some one could help me figure out how to say dim the light to 60% after 10pm lol
I have tried to create this in the visual editor. Yaml code as follows
description: ""
trigger:
- platform: sun
event: sunset
offset: 0
- type: motion
platform: device
device_id: 7667cfee7c70159c4879bda5f3a778bd
entity_id: be924323c013961b6cba9714e19d71ca
domain: binary_sensor
condition: []
action:
- type: turn_on
device_id: f1e6d9fd56509eb7331be5689c38a458
entity_id: c4170ef8ab9b859ddf03794d4a60ffb2
domain: light
- type: is_no_motion
condition: device
device_id: 7667cfee7c70159c4879bda5f3a778bd
entity_id: be924323c013961b6cba9714e19d71ca
domain: binary_sensor
for:
hours: 0
minutes: 1
seconds: 0
- type: turn_off
device_id: f1e6d9fd56509eb7331be5689c38a458
entity_id: c4170ef8ab9b859ddf03794d4a60ffb2
domain: light
mode: single```
the light comes on but doesnt switch off
what cant i see?
First off, I (and many others) would recommend against using device triggers/conditions/actions. There are several reasons but I wonât list them here but if you do a search you should be able to find a post about it.
you should try to use other triggers like state/numeric_state/etc. And services as actions.
And the logic you have (obviously) doesnât work like you think it will.
the second action wonât sit around and wait for the 1 minute you have. As soon as the light gets turned on it will immediately check to see if the condition is met (that there has been no motion for a minute) and will take the next action ifd that check is true.
in your case it is impossible for the motion to trigger the light to turn on and then a millisecond or so later also there has been no motion for a minute.
There are a couple of ways to do what you want tho.
you can use two triggers (one for motion and one for no motion) and then choose which action to take based on which trigger happens.
Or you can use one trigger to turn on the light and then in the actions section after the light is switched on use a âwait_for_triggerâ that will be no motion for 1 minute then turn off the light.
The first option is a bit more complicated but itâs more resilient than the wait option.
Since you didnât give the entities I can give a basic outline of the first option but youâll need to find your entity_idâs to replace the examples with:
So the light doesnât keep going off and on when motion is detected during the 1 minute windowâŚ
When motion is detected within the one minute, it should stop the running action, and restart it
For that reason, I would also increase the time to 3-10 minsâŚbut it depends a bit of the location of the detector
And yes⌠stay away from devicesâŚtry to use entities, it will libe a lot easier when something needs to be replaced
you can just import this by going into automations,
Create a new automation, and then enter edit yaml mode (found in the 3 little dots in upper right corner)
Select all, and copy paste my code into it.
(but off coarse correct the sensor/light name 1st)
Yes, that works but was mentioned as my second option which is less resilient to restarts etc.
I assumed the cool-down period of the motion sensor was longer than 1 minute.
And it really doesnât make any sense to add that the âlight will be going off and on during that minuteâ when there is nothing in that minute to turn the light off until the minute expires.
so worst case is that the light keeps getting turned on. but since itâs already on no one should notice.
And yes, you could use the âoffâ condition of the motion sensorâŚbut them you also have to take that delay into accountâŚand few of mine are triggered by mqtt, which doesnât have an off state, they just trigger once
Last question i tried to follow logic and lets say after 10pm i wanted the light to dim so it didnt âblindâ anyone walking over the landing
I tried this
description: Off 1 min after on (and no motion), dim to 40% after 10pm
trigger:
- platform: state
entity_id:
- binary_sensor.landing_sensor_motion
from: "off'
to: "on"
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: light.turn_on
target:
entity_id: light.landing_light
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: light.turn_off
target:
entity_id: light.landing_light
- condition: time
after: '22:00:00' # After 10pm
- service: light.turn_on
target:
entity_id: light.landing_light
data:
brightness_pct: 40
mode: restart```
But it still came on at 100%
50mins before sunset if the landing sensor detects motion turn on tbe landing light to 100% then turn off after 2 minutes. You added before a line to keep the automation running if motion is detected againâŚ
Then i wanted between 2130 and 0730 if motiom was detected then turn the light in dimmed to 30% turn off after a minute. Automation stops at 730am
I could get it working but it would turn the dimmed light off post 2130
So what happens if the motion sensor never turns off because you are still in the area? If it never turns off because it is continuously detecting motion then it would never need to turn turn back on.
The way you have it programmed now after 2 minutes the lights turn off regardless of if motion is still being detected.