I don’t know how to best script this, because my tries so far are failing miserably.
In our bath room I have a motion detector that is scripted to turn on/off lights after certain time. This works flawlessly. However, if someone wants to take a bath we don’t want the motion detector to control the lighting in the bathroom for a set time (30 minutes).
I thought it would be an easy fix setting up an input_boolean.bath. I have a blueprint / automation for our Fibaro Keyfob which is used in the bathroom. I made a scene for the bath light settings. I then set this up for one of the buttons:
And then in the motion detection automation I included input_boolean.bath to block it from going on/off if the input_boolean.bath is on. Technically it works, the automatic lighting is blocked for 30 minutes.
However the problem is that Keyfob is completely unresponsive to any other presses until the delay timeframe (30 minutes) is up. I tried moving everything to a script and just have the blueprint / automation for Keyfob run the script and not have the actual delay in the automation itself, but it renders the same end result. The Keyfob is unresponsive for the duration of the delay.
So I figure there must be a better way of doing this. Thus disabling the motion sensor / automatic lights for 30 minutes with a button press and still be able to use the rest of the buttons.
And as a side question. If you run a script with a delay command and you then run another script in the timeframe, will the first script still trigger after the delay is up or will it get cancelled by the second script changing the entitty ahead of time?
Instead of your boolean and delay method use a timer helper. Getting rid of the use of delay and making sure the mode is set to one of the options other than the default single should help the unresponsiveness issue.
Then in your automation, include the timer as a trigger and condition as appropriate.
If you need help doing that, post the motion light automation you are currently using so we can integrate everything in one place.
The only way I could get the UI to accept the code was with it like below. This is part of a remote with lots of buttons. Should the mode: restart be for them all or specifically the button with the timer?
Now that you have posted the blueprint you are using we can actual see how things are supposed to work together… and what’s possible within the framework. The mode of the blueprint is set to single. To make that work and avoid the unresponsiveness, you need to avoid delay or wait within the actions. The timer method should work fine. If you find you need a sequence that includes a wait move it to a standalone script. The reason you had issues with that method previously is that you likely didn’t use the correct method to call the script and avoid waiting for it to complete.
Gonna try this in just a bit. Before I start, how can you determine that the blueprint mode is “single” ? Or is this the default if not defined?
Would it be better changing the whole blueprint to “restart”. Can’t really see why or what is better with single compared to restart? There are no advanced actions. The scences include two light entities. Other buttons are just controlling mediaplayer (sonos).
Also a second question now that came into mind now that you introduced the timer function.
The motion detection for the bathroom is split in four automations, two for on (one daytime and one nighttime) and two for off (also different timing for day and night).
The off scripts trigger is just when motion sensor goes to ‘off’ for 5 minutes (listed below).
Would it be better/cleaner just to have one script for ON and using the timer function as well so the lights go auto off after timer? Instead of separating on and off to different automations? Any certain pros/cons?
trigger:
- platform: state
entity_id: binary_sensor.bad_motion
to: 'off'
for:
hours: 0
minutes: 5
seconds: 0
The default mode is single, but it is explicitly defined on line 101 of the blueprint.
If your actions are short and you don’t normally press buttons repeatedly (like you might to change volume, skip tracks, or change brightness) or in sequence, it should be fine in “restart”, otherwise “queued” might be a better option.
You will need a timer event trigger and related conditions to choose when turning off is appropriate.
It is best for you to set it up in whatever way makes sense to you. Some people like lots of small automations and scripts, others prefer to have more complicated automations that cover every aspect of how a single device operates…
You are one step ahead of me. Didn’t realize you looked at the whole blueprint, thought you distinguished it from my cut out bit of code
Single seems like the better choice then since volume presses can be frequent presses.
The LIGHT ON automations are simple enough. Adding this condition should keep it from changing any of the lights as long as the timer is on:
condition:
condition: state
entity_id: timer.bathroom_light
state: 'idle'
However little bit more unsecure on the OFF automations. If I add the condition above (changed to active), then there might be situations where there won’t be a new trigger once the timer is off and the lights will stay on indefintitely.
My best solution to this would be to add even more automation with the finished timer as trigger and action is a on and off toggle of the motion sensor. That way the lights will go off if no motion for an additional five minutes? I am sure there is a better way of doing the off automations?
Is there any latency issue or stability with split automations or everything in one?
Played around all night and day and think I got everything working like I want now.
Ended up cleaning up all the automations and making it into one big one using trigger ids.
Everything seems to be working. Different lighting depending on sun state. Different off depending on time of day. And when triggering bath script timer “pauses” light automation until finished then it kicks back in again.
BIG thanks for your help @Didgeridrew , couldn’t have done it without you!