I am the first one to like this new automation
Nice one, hopefully more people will like it once they know about it and understand what it can do.
Blacky
Now we are talking. Will give this blueprint a try with my current setup. This seems to solve the exact use case I mentioned in the Sensor Light topic.
Thank you very much for this blueprint.
Thanks @Blacky exactly what I was asking for!
I have configured it and I it works as designed
I have a few suggestions:
Allow a door contact to also pause the time (Wasp in a box scenario) Especially if you donāt move light can be turned off, when just having a motion sensor, not a presence sensor.
Allow to trigger by area. So If I turn any light on in the room, the automation is triggered also turns of everything in that room. When I add or remove a light, I donāt need to touch the automation again as the area is updated in the background.
Your welcome, hope you like it.
Black
Nice one thanks for the feedback.
Have you seen my Bee In The Hive Sensor ? It will do what you are asking. To find out more about it and how to do it click here. You would use this sensor in a group with your motion sensor and add it into Motion Sensor - Binary Sensors input.
I have a look at that and add it to my list. Thanks for the suggestion. Just a question what if there are a lot of items in the area? It will turn ON and OFF everything
Blacky
Excellent, apologies been away so missed your other reply. This looks ideal, will load it in and have a play.
My first attempt of using a timer in an automation so might be me.
The timer I created pauses when there is motion and then on clear continues to run down.
SO a 5 min timer is ticking down but if I move at say 1 min, it then waits for clear then resumes? Rather than resetting back to 5 mins?
So its better to not use a helper if you want a full 5 min āclearā state for the action?
Assuming that is the intent, I changed to the straight timer and set at 2 mins for testing.
Now on a reboot, in my testing it didnāt work. I think because there needs to be a delay between HASS restart and the decision being made if a light is on so to restart the timer? In my case lights are connected over Zigbee2MQTT and it takes some seconds before the state is known on a restart. Not sure the right number but guess it depends on each setup, maybe needs a long delay of say 1 or 2 mins, or a user defined option to set based on user environment?
Test - Light is on. Restart HASS and leave room. Wait to see if light turns off after reboot + the delay time.
For restart the trace shows:
I did think that once Z2M loaded the light being recognised in the ON state might trigger the new instance of the automation anyway, so saves having any delays or need for that, and start the timer but it didnāt?
So this is trace of light on with reboot. then the room being empty without motion to trigger the automation.
The light going unknown then On (when Z2M restarts)
Might it be better to have the trigger going from anything to ON rather than from Off to On as a trigger?
I have tested it again here and when the light is on and motion is detected it pauses then resets when motion is cleared.
I will check the restart later when no one is using our HA.
Blacky
I have tested it here on a restart.
Manual light ON + timer ON + No motion and I got this.
So now it is waiting for the timer to go OFF and when it did I got this lights OFF.
My light state stays ON when HA restarts, so if it is Zigbee2MQTT then we need a work around.
One thing that comes to mind is template sensor. Below is a example of the code used in a binary template sensor. When you restart and your light is unavailable or unknown and the timer is active or paused it will be ON
Go to Settings > Devices & Services > Helpers Tab at the top > Create Helper > Template > Binary Sensor and in āState Templateā paste the code below replacing the two inputs with your entity IDās
{% if is_state('light.your_light', ['unavailable', 'unknown']) and
is_state('timer.your_timer', ['active', 'paused']) %}
on
{% else %}
off
{% endif %}
Once done add it to Trigger - Lights & Switches adding in another light or switch then edit in yaml and replace the entity ID with your template sensor.
Blacky
Oh my days, the helper timer is working now. Wonder if I need to restart HASS after setting the timer up. Weird. It was honestly pausing then carrying on from where it was earlier!
On a restart it did just continue too. The timer was at about 15 secs when the light state went from unknown to On. So this time it did indeed turn the light off.
Test 2 - with the Helper timer, I let it run to around 45 seconds then did the restart of Hass. I kept a screen on with the dash showing offline, though the countdown continued. By about 3 seconds the light went to unknown, timer continued to 0. nothing (as light not displayed as On). Light eventually changed to On after another 20 seconds or so but the timer was now Idle. No movement and assume light will stay on forever.
Not tested without the helper timer and just the default in the bluerprint yet.
I am convinced its linked to the delay with Z2M for light state. Seems to need at least 60 seconds from a restart to then trigger the automation. Maybe that is a solution? Restart = wait 60 seconds before taking action?
Tried the template you suggested, changing the items for light and timer. Canāt add, is the entity list restricted to only light or switch currently for a trigger?
Although to combat the delay from Z2M, wouldnāt a state change from anything to On work as would just trigger a new run of the automation assuming the light had been activated/switched on ? Where currently seems to ignore an Unknown to On as a trigger?
I have just tried that by commenting out the line in the blueprint for from off to on as a trigger - line 149
Rebooted at 45 secs with the light on, by the time it got to 0 timer went Idle and light was on but showing āunavailableā. Bit later when the light was detected to On again the timer started and once complete it did turn off.
That feels like a reasonable solution that works for most folk?
Thanks for all your testing and information. I will have a look at it.
Just add in a switch or a light (donāt worry you will replace this), then edit in YAML (3 dots to right). Then replace your light or switch entity id you just added in with your template sensor entity id and click save.
So it did get there in the end.
Blacky
So it did get there in the end.
Blacky
[/quote]
Yes but only with the āoffā to āonā trigger changed to an āonā trigger. Otherwise it wouldnāt trigger until there was more motion, which could be the following day/week.
Okay thanks for the info
This is awesome! It would be great if this worked with ceiling fans as well.
Is your ceiling fan a switch?
Blacky
It looks like the entity is of type āfanā.
On a separate note, I am testing your blueprint on a light. It works fine except when I disconnected the occupancy sensor from the network. When I manually turn the light on, it immediately shuts off. I will add that for testing I had set the timer to 1s.
Okay, maybe I should update it so a switch can be anything (any domain other than a light).
Your best to use the bypass for manual control.
Blacky
Can this be time based so from 5pm to 10 pm lights stay on for 10 min and 10:01 pm until next day 4:59 PM lights stay on for 5 min.
Since I only have a door binary sensor that is Open or closed I changed these settings to accommodate resting the helper timer when the door is re-opened. I have Kasa motion sensors and they dont allow for HA to see motion status.
420 - alias: Ceck if the timer is idle
conditions:
- condition: state
entity_id: !input timer_helper
state: Closed
449 - alias: Ceck if the timer is idle
conditions:
- condition: state
entity_id: !input timer_helper
state: Closed