šŸŖ„ Manual Light Control With Auto OFF

Your welcome, hope you like it.

Black :smiley:

Nice one thanks for the feedback.

Have you seen my :honeybee: Bee In The Hive Sensor :honeybee:? 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. :+1: Just a question what if there are a lot of items in the area? It will turn ON and OFF everything :thinking:

Blacky

1 Like

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)
image

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 :smiley:

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 :wink:

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 :smiley:

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 :smiley:

So it did get there in the end.

Blacky :smiley:
[/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 :smiley:

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.

@youghta

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 :smiley:

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

Thanks. Im a bit confused by the response to the second item since the point of your blueprint is to allow for manual control with auto off. What Iā€™m seeing is that when the proximity sensor is offline, the blueprint shuts the light off. I would hope that it would do the opposite and not shut the light off and only return to normal operation when the sensor is back online.

@kobejo34

Currently there is only one time delay. You may be asking that when you open and close the door you would like it ON for 10 min or 5 min depending on time. If this is the case then have a look at my sensor light blueprint and you can use night lights with a different time delay.

Blacky :smiley:

@youghta

The triggers must go from ON to OFF or OFF to ON.

Blacky :smiley:

@benkly

Just a quick note. If you donā€™t use the timer then delay will be used and in the top post it gives you examples on how it handles a HA restart.

Day/time is not to be confused with delay or timer. It is not the same. Day/time is exactly thatā€¦ set day/time. Delay or timer is not exact day/time. This blueprint can be triggered at any point and when it turns OFF is not a exact day/time.

FYI: Below are 2 examples for day/time v timer. There are many ways to handle this in your automation code it just depends on what option you choose. No way is wright or wrong.

Day/time = If you have X running for 3 hours and 20 sec before it is about to turn OFF you restart HA. At that point you are using a day/time trigger to turn it OFF. HA takes 30 sec to restart and your time/day trigger has been missed. It will not turn X OFF.

Timer = If you have X running for 3 hours and 20 sec before it is about to turn OFF you restart HA. HA takes 30 sec to restart and your timer resumes after the 30 sec and start the 20 sec left on the timer and turns X OFF. Yes it ran for an extra 30 sec but it is OFF.

Again you can make anything work it just depends on your code and what you would like to do. You could make day/time work in the above scenario but you will need the code to handle that. This blueprint needs delay or timer as it is not a fixed day/time. It triggered from the time you turn the light or switch ON.

Hope this gives you a better understanding.

Blacky :smiley: