Hi,
I have several motion detectors and would like a simple way of turning off a light after 10 min from the motion detect.
Should I use the automations tab, blueprint or just a script?
Thanks
Hi,
I have several motion detectors and would like a simple way of turning off a light after 10 min from the motion detect.
Should I use the automations tab, blueprint or just a script?
Thanks
There is actually a tutorial to do pretty much what you want i.e. create an automation and test it to get it working then convert this into a Blueprint that can be re-used for different lights/motion sensors.
To achieve what you are after you would need to modify the trigger to fire after 10 mins without motion being detected.
trigger:
platform: state
entity_id: binary_sensor.motion_kitchen
to: 'off'
for: 00:10:00
You could also simplify the action if you only wanted to turn the light off.
I do it with automations.
like this:
alias: Raaf ledstrip uit pir
description: ''
trigger:
- type: no_motion
platform: device
device_id: bd3b03f2e3c1bd71519e781ffdee36b2
entity_id: binary_sensor.neocam_pir_raaf_home_security_motion_detection
domain: binary_sensor
for:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
condition:
- condition: state
entity_id: light.raafledstrip
state: 'on'
action:
- service: switch.turn_off
target:
entity_id: switch.sonoff_10008c3a5b_2
mode: single
id: '1632855330323'
alias: Guest Bathroom Light Motion Auto
description: ''
trigger:
- type: motion
platform: device
device_id: 51ea75a5d7a9d656edf9821523bc6791
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
domain: binary_sensor
for:
hours: 0
minutes: 2
seconds: 0
milliseconds: 0
condition: []
action:
- type: turn_off
device_id: 51ea75a5d7a9d656edf9821523bc6791
entity_id: switch.in_wall_smart_motion_switch
domain: switch
mode: single
I tried this and it does not turn light off after 2 min or any minutes?
compare yours and my code, you are almost there…
ok. I compared it and it still does not turn off? Does it make a difference if its in automations/yaml?
in condition: should that entity_id be: light.binary xyz or light.switch…?
- id: '1632855330323'
alias: Guest Bathroom Light Motion Auto
description: ''
trigger:
- type: motion
platform: device
device_id: 51ea75a5d7a9d656edf9821523bc6791
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
domain: binary_sensor
for:
hours: 0
minutes: 2
seconds: 0
milliseconds: 0
condition:
- condtion: state
- entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
- state: 'on'
action:
- service: switch.turn_off
- target:
entity_id: switch.in_wall_smart_motion_switch
mode: single
if i understand it right, trigger has to be no_motion?
the condition is not necessary, it just makes, that nothing happens, when the light is already off.
I also have it in automations.yaml
It triggers when there is motion. Light goes on when motion triggered. Then goes off after 2 minutes.
Anyone see why this is not working?
- id: '1632855330323'
alias: Guest Bathroom Light Motion Auto
description: ''
trigger:
- type: motion
platform: device
device_id: 51ea75a5d7a9d656edf9821523bc6791
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
domain: binary_sensor
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition:
- condtion: state
- entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
- state: 'on'
action:
- service: switch.in_wall_smart_motion_switch.turn_off
- target:
entity_id: switch.in_wall_smart_motion_switch
mode: single
Well THREE things, depending on whether you have pasted the code here exactly, if you have - then your entity_id under target need to be indented.
Additionally, why are you not triggering on no_motion, instead of motion? You probably won’t record motion for a whole minute, it likely switches to no_motion, in less than 30 seconds, so the trigger never happens.
- service: switch.turn_off
- target:
entity_id: switch.in_wall_smart_motion_switch
Also - the service is switch.turn_off, you don’t include the device in the service, that’s what the entity_id is for.
EDIT:
And this still won’t really be what you want. Unless you change the mode to restart, what is going to happen here is that the light will ALWAYS switch off 1 minute after it stopped detecting motion, regardless if whether it started detecting motion AGAIN. So if this is really what you want, then your light will be going on and off every minute as you move about in the room.
I’ve told you…
And why a second thread for the same problem?
@BebeMischa, @mobile.andrew.jones
Ok. I made the recommendations you both gave. I don’t see the light turning off after 1 min? Is there something I missed, again?
Updated code:
- id: '1632855330323'
alias: Guest Bathroom Light Motion Auto
description: ''
trigger:
- type: no_motion
platform: device
device_id: 51ea75a5d7a9d656edf9821523bc6791
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
domain: binary_sensor
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition:
- condtion: state
- entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
- state: 'on'
action:
- service: switch.turn_off
target:
entity_id: switch.in_wall_smart_motion_switch
mode: restart
Replace
condtion: state
by
condition: state
too many dashes. A single dash represents each condition, you’ve added it to each line of a single condition, effectively splitting it up. Also, as @browetd pointed out, you’ve misspelled things.
- condition: state
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
state: 'on'
Also, mode: restart
is indented too much. It should be in-line with trigger, condition, description, and action.
action:
- service: switch.turn_off
target:
entity_id: switch.in_wall_smart_motion_switch
mode: restart
@browetd
Good catch.
@petro
I made the adjustments and the editor gave me a green checkmark. I saved and triggered the motion but it did not turn off after 1 min?
I believe I am working with these sensors and switches.
Looks like my reply was hidden for some reason? I don’t know if you can see it or not? or respond?
Are you following the logic yourself or just asking people to fix it for you? Does your current condition make sense based on what entities it’s checking?
If this REALLY matches the indentation in your code - then it’s way off:
target:
entity_id: switch.in_wall_smart_motion_switch
It 2 spaces every time you go in a level. It looks you have probably pressed tab twice instead of space.
hang on, hang on - wait…
condition:
- condition: state
entity_id: binary_sensor.in_wall_smart_motion_switch_home_security_motion_detection
state: 'on'
What is this for? This says the condition of the automation running, is that the motion detected is on - ie it is currently detecting motion, but the trigger of the script is that no_motion is detected.
What is the point of this condition? Were you by any chance actually wanting the condition to be that the LIGHT is on? In which case it would be:
condition:
- condition: state
entity_id: switch.in_wall_smart_motion_switch
state: 'on'
Just noticed that myself…
At this point, I don’t even know what the objective is anymore…
Nothing makes sense.
FYI, yaml spacing only matters for the current level. You can have uneven spacing and it won’t matter. I.e. this is valid:
hello:
uneven:
space:
count: 10
lined_up_with_uneven:
my_spacing_only_matters_for_current_field: 4