thank you @_Xander, much appreciated! I was able to follow and re-do this at my end, seems to work now. Thanks again for taking the time to help a newbie!
Could you elaborate on this please, I am not very good with helpers yet
Simply create a new empty automation, go to the … on the top right and choose yaml. Then you can simply paste the code from above.
It has nothing to do with “helper” as used in the GUI. It is simply an extra automation that toggles the functionality of the YAMA one. You could also use the YAMA incorporated blocking variable to prevent YAMA from functioning, but that one is imho not always useful since it leaves the current (light) state forever. A second automation as described above prevents this since I simply always also turn the light off when the automation is switched off.
Perfect, thank you
2nd scenario
Bathroom motion lights
I want the automation to not turn off the lights while I’m in the shower. Bathroom has a humidity sensor. Usually sits around 65 but jumps quickly to 70+ when shower is running.
I created an threshold helper with upper limit 70 with humidity sensor as it’s entity and then added it as a no motion blocker in ON position but it’s not stopping the lights from turning off when shower is running
Because the humidity could change from one day to another, an idea to improve the behavior would be:
First we create a sensor that generates the humidity average over last 30 minutes or last hour.
sensor:
- platform: statistics
name: Bath Humidity Average
entity_id: sensor.sonoff_temp_humidity_sensor_humidity
sampling_size: 40
max_age:
hours: 1
state_characteristic: average_linear
And then we do a helper binary sensor, to compare realtime humidity and the average. If the difference jumps beyond, say, 5%, we consider it a shower event:
template:
- binary_sensor:
- name: "Showering"
unique_id: showering
device_class: motion
state: >
{{( states('sensor.sonoff_temp_humidity_sensor_humidity') | float(0) ) >
( states('sensor.bath_humidity_average') | float(0) + 5 ) }}
Anyways, my 2 cents. Feel free to adapt the config to meet your need.
Thats sound like it will work. Much appreciated. Giving it a go !
To have it completely independent of the actual average, you can also create a helper sensor being the derivative of the humidity sensor. This derivative will immediately become quite high when the showering starts, so make an automation that turns off the YAMA when dHum > 100. Turning it back on depends a bit on your situation, does your shower have good mechanical ventilation, then you can turn it back on as soon as the dHum < -10, indicating the moment where the humidification is starting to decrease. Another possibility of course is simply a wait timer to turn it back on.
I have a problem that the light automatically turns on before sunrise, but when it is after sunset, it does not want to turn off.
See above for a possible solution using a second automation.
@networkingcat would it be possible to create a version with blocking boolean that only blocks the turning on, or ideally change the current blocking bool to only starting a new sequence and create a second bool entry that blocks tuning off.
Is it possible to add a 2nd no motion blocker motion sensor to this?
Easiest way: create a helper boolean and feed all desired blockers into that one and only use the helper bool in YAMA.
Harder way: edit the blueprint to include another one or edit the blueprint to also accept a template where you can also use as many bools as you would like…
I have setup an automation blocker, so lights do not get turned on, when it is not dark (via helper).
Am I right, that this leads to some kind of loop whole?
i.e. when it is dark, motion is detected, then lights turn on. While the lights being on, it gets so bright, that the automation blocker kicks in. So the lights will stay on all day.
Yes, that is one of the flaws of this YAMA blueprint, so for now my solution is next to every automation I have a YAMA extra automation:
alias: Hallway - YAMA lux block repair
description: |-
ALS
EN YAMA block on (high lux, genoeg licht)
EN lamp = aan
DAN lamp uit
ALS
EN YAMA block off (niet meer genoeg licht)
EN beweging gedetecteerd
DAN lamp aan.
trigger:
- platform: state
entity_id:
- binary_sensor.lux_high_hallway
for:
seconds: 10
condition: []
action:
- if:
- condition: and
conditions:
- condition: state
entity_id: light.relais_hallway
state: "on"
- condition: state
entity_id: binary_sensor.lux_high_hallway
state: "on"
then:
- service: light.turn_off
data: {}
target:
entity_id: light.relais_hallway
else:
- condition: and
conditions:
- condition: state
entity_id: light.relais_hallway
state: "off"
- condition: state
entity_id: binary_sensor.motion_hallway_occupancy
state: "on"
- service: light.turn_on
data: {}
target:
entity_id: light.relais_hallway
mode: single
Got an extremely simple motion detection trigger light to start, but it is not working.
This is the automation code:
mode: restart
max_exceeded: silent
variables:
scene_ambient: scene.none
scene_morning: scene.none
scene_day: scene.none
scene_evening: scene.none
scene_night: scene.none
automation_blocker: null
automation_blocker_boolean: false
no_motion_blocker: null
no_motion_blocker_boolean: false
elevation_check: none
scene_no_motion: scene.none
motion_entity: binary_sensor.motion_voordeur_motion_detection
trigger:
- platform: state
entity_id: binary_sensor.motion_voordeur_motion_detection
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.motion_voordeur_motion_detection
from: 'on'
to: 'off'
for: 120
condition:
- condition: or
conditions:
- '{{ automation_blocker == none }}'
- >-
{{ automation_blocker_boolean and states[automation_blocker].state ==
'on' }}
- >-
{{ not automation_blocker_boolean and states[automation_blocker].state
== 'off' }}
- condition: template
value_template: >-
{{ (elevation_check == none) or (state_attr('sun.sun','elevation') <=
elevation_check | float(90)) }}
action:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == ''on'' }}'
sequence:
- choose:
- conditions:
- '{{ scene_morning != ''scene.none''}}'
- condition: time
after: '00:00:00'
before: '00:00:00'
sequence:
- scene: scene.none
- conditions:
- '{{ scene_day != ''scene.none''}}'
- condition: time
after: '00:00:00'
before: '00:00:00'
sequence:
- scene: scene.none
- conditions:
- '{{ scene_evening != ''scene.none''}}'
- condition: time
after: '00:00:00'
before: '00:00:00'
sequence:
- scene: scene.none
- conditions:
- '{{ scene_night != ''scene.none''}}'
- condition: time
after: '00:00:00'
before: '00:00:00'
sequence:
- scene: scene.none
default:
- service: light.turn_on
target:
entity_id: light.hal_onder
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == ''off'' }}'
- condition: or
conditions:
- '{{ no_motion_blocker == none }}'
- >-
{{ no_motion_blocker_boolean and states[no_motion_blocker].state
== 'on' }}
- >-
{{ not no_motion_blocker_boolean and
states[no_motion_blocker].state == 'off' }}
sequence:
- choose:
- conditions:
- '{{ scene_ambient != ''scene.none'' }}'
- condition: time
after: '00:00:00'
before: '00:00:00'
sequence:
- scene: scene.none
- conditions:
- '{{ scene_no_motion != ''scene.none'' }}'
sequence:
- scene: scene.none
default:
- service: light.turn_off
target:
entity_id: light.hal_onder
id: '1668437140894'
alias: 0 - Lamp Hal onder (motion)
description: ''
But it fails on the sun part of the automation, which i’m not using (see automation above)
Does anyone understand why this is going wrong?
I use Neo Coolcam (Z-wave) Motion sensors
Maybe elevation should be empty, 0 or false?
Easiest way: Install this blueprint according to the manual, restart HA and then create the following automation:
- id: '1668437140895'
alias: 0 - Lamp Hal onder (motion)
description: 'Automatisch schakelen licht in de hal obv voordeur detectie'
use_blueprint:
path: networkingcat/yet_another_motion_automation.yaml
input:
no_motion_wait: 120
# This means: 120s after the sensors internal blocking mechanism, perhaps as long as 90s?
# If you want 2 minutes after you left the room, lower to 30.
motion_entity: binary_sensor.motion_voordeur_motion_detection
# Check for correct sensor name, doesn't it end in "_occupancy" ?
light_target:
entity_id:
- light.hal_onder
Automation reload() et voila, it should work.
(since you don’t use a blocker bool, no need to add the extra automation is wrote above)
I’m not sure what you mean exactly.
When i copied above yaml as a new automation, i get an error:
Message malformed: extra keys not allowed @ data['0']
Not sure what it means.
Probably it fails because of the “_occupancy”, remove all lines with # and try again. Or it cannot find the correct blueprint? Did you install the blueprint in the correct way, is it located in home-assistant config dir?
Otherwise you could install it using the HA mode: Create a link – My Home Assistant
Check afterwards if it is installed in folder home-assistant\config\blueprints\automation\networkingcat\yet_another_motion_automation.yaml
restart HA, reload the page in your browser (CTRL-F5)
Then go to automations, click “+ create automations”, choose the correct blueprint and fill in only the first three fields:
- motion sensor entity (choose correct entity, iets met voordeur en occupancy, icon with moving person)
- under light, click choose entity and choose the light for the hallway
- wait time 120 (see remark above)
Click save and give it a name, reload automations (developer tools → click automations, wait for green mark) Now it should work…
Hey, thanks for this blueprint, I have moded it (actually mostly copy/pasted from another blueprint) to only switch on the light while a light sensor reports the lux level below a threshold.
I could share my fork, but dont know if its “allowed” to just hijack the thread?
Basically have added variables and a condition for the “on” state trigger.
Also saw someone mentioning that lights arent switching off after sunset, shouldnt the elevation check also move to only check inside the “on” trigger conditions to fix this?
How do I set this up to check if I am at home? Or, my presence is in that specific room?