I tried searching for a solution but can`t really get the hang of it… and with the visuelle Editor my plan can´t be done. So I had to try with YAML but it doesn´t work.
My plan is that the light turns on for 1 Minute if motion is detected and Lux is below 30.
Everything works, my only problem is the Timer, that it doesn´t turn off again after 1 minute.
First, go back to the UI editor
Then it is quite easy, let me do it plain English for you
Trigger
motion + add id → motion
end of timer + add id → timer_end
Conditions, remove as it will prevent the timer_end trigger
In your actions, add 2 if / then action
if triggered by motion AND lux below 30 then turn on the lights and start the timer
if triggered by timer_end then turn_off the lights
Also, change the mode to restart so it will restart your 1 minute timer if motion is detected during the 1 minute of light and you’ll not end in the dark.
By the way, I’m not a blueprint guy but have a look, what you try to do is very “common”.
EDIT You can create a timer in Settings > Devices & Services > Helpers
I feel like a lot of stuff can only been done with the YAML Editior and not via visuelle Editor
Another question: Is it possible, that the delay is resets if the binary sensor catches motion again.
So that the lights dont go off and on again after 1 Minute, when im still running around in the hallway?
Sorry for the delayed answer!
Yes and it works perfect, after I knew how it worked I changed all my automation so they have a timer included. Befor I had a lights on automation and lights off automation, and then for weekend. So there where like 20 Automation and now I have only 7
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
There is a problem with the Automation.
The Automation triggers if I walk in the hallway and the motion sensor triggers, the problem is as long as it detecteds motion the hole time the timer doesn’t restart and the lights turn off after 30 seconds, but if it doesnt detected motion for about 5 seconds, the timer restarts (I stopped the time to measure it)
The detection_interval is set 2 seconds of the motion sensor and I checked in Zigbee2mqtt, if the motion detection triggers from off/inkativ to on/aktiv the lights go on perfect like it should, but if then if it triggers very fast like under 1 second form on to off to on ( I waved my hand in front of it), the timer doesn’t restart, but if it is off/inkativ for like 3-4 seconds and the detected motion againt the timer restarts.
Kinda hard to describe whats the problem, but I hope somebody understands what I mean and knows a solution for it.
Perhaps you can reverse the automation.
So set up a trigger when there i no movement for 30 seconds and make this turn off the lights.
Then have another trigger when there is movement to turn them on.
When the motion sensor turns on, there’s no need for it to trigger the automation unless the light level is below 30.
If you don’t make that part of the automation’s trigger or condition, and only check the light level in the automation’s action, it means the automation will be executed (and its last_triggered updated) every time motion is detected regardless of the light level.
Here’s one way to restrict execution to only when needed:
alias: example
description: ""
trigger:
- platform: state
entity_id: binary_sensor.0x54ef4410007761a6_occupancy
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.0x54ef4410007761a6_occupancy
from: 'on'
to: 'off'
for:
seconds: 30
condition:
- condition: template
value_template: >
{{ trigger.to_state.state == 'off' or
(trigger.to_state.state == 'on' and
states('sensor.0x04cf8cdf3c8a20ff_illuminance_lux') | float(0) < 30) }}
action:
- service: "light.turn_{{ trigger.to_state.state }}"
target:
entity_id:
- light.0xa49e69fffe94d9a3
- light.0xa49e69fffe9a3355
mode: single
The automation’s condition can be refined even further and only turn the lights off if they are currently on (and turn on only if they are currently off).
condition:
- condition: template
value_template: >
{% set lights_on = ['light.0xa49e69fffe94d9a3', 'light.0xa49e69fffe9a3355']
| map('states') | select('eq', 'on') | count %}
{{ (trigger.to_state.state == 'off' and lights_on > 0) or
(trigger.to_state.state == 'on' and
states('sensor.0x04cf8cdf3c8a20ff_illuminance_lux') | float(0) < 30 and
lights_on < 2) }}