#Automate light getting progressively "angrier" based on standing desk low timer

1 messages · Page 1 of 1 (latest)

hearty laurel
#

So, I am trying to automate a light to get progressively angrier at me the longer my standing desk is in the down position. To trim down the requirements slightly, I essentially want to have a wall light change scene after 2 hours of the sensor being in the closed position (desk in sitting mode). Once that 2 hour mark is hit, every 5 minutes, I would like the light to change to a scene for 1 minute, and then change back again. If it gets to 3 hours, I want to change to another scene until the desk is in the up position.

if at any point the sensor goes to the open position, then the light scene should go back to normal, so no 5 minute change, no 3 hour final scene, and if its before the 2 hours, then essentially it should no longer matter.

To add some additional complexity, I would like the 2h timer to start from when I walk into the room (not at a fixed time), and, I don't want it to get angry at me outside of 8am and 5pm. So for example, if the timer starts at 3:30.. next "angry" would be 5:30.. which shouldn't fire because its outside of the 8-5 window.

What I have tried?
So, my first attempt at this was to create an helper timer. I then setup an automation to start the timer when a motion sensor gets triggered.

Next, I setup another automation to cancel the timer when the desk is in the open/standing position.

Third, I setup another automation that triggers when the timer ends (ie, reaches 2 hours). This then runs a script that loops until the desk sensor is in the open position. The loop essentially set the angry scene, wait 1 minute, sets the normal scene, waits 4 minutes and keeps looping with a repeat index off 11 (which should mean it does it up to an hour).

The problem with this approach was that the desk script seems to continue running as the until doesn't seem to be checked very often. So you would end up with thing happening while the script continued to run.

#

Does anyone know a better way to do this, or should I just continue debugging this until I manage to get the script way to work?

sonic folio
#

Well one way to simplify this a lot is with binary sensors and a group
Add your motion sensor, desk down sensor and a time of day helper (set to 8-5) into a binary sensor group set to all entities and then you can trigger off that being on for 2 hrs etc (this does assume your motion sensor stays on when you are sitting at the desk)

hearty laurel
#

Ooo, ill give that a shot, i may leave the motion sensor out of it, as goingn to get a drink may affect it. I think the essential is the timer should start on the first motion activation of the day.

#

ity sounds like a plan to do it as a binary sensor group though, it will help the debugging too

sonic folio
#

As for the script being annoying... Yeah that's a bit tricky, the check only happens at the end of the loop, not during it

hearty laurel
#

Yeah, i wonder if coding in some if statements (a/b).. if the desk is still down after the wait, then do the scene. If not, then skip it. At worst it would mean I see the angry scene for 1 minute.

#

actually...

#

until (desk up) { angry scene > 1 minute > normal scene > 4 minutes }

If the until checks at the end, that should just work.

#

it wouldnt work in testing if i put the desk up and down too fast

#

but in real use thats probably not going to happen

sonic folio
#

What you could do instead is use a "wait for trigger" checking for your group to be off with the timeout being set to 1/4 minutes - this could be used to skip through the timers quickly when the desk is up.
Another option is a separate automation that can run the script.turn_off action to break you out of the loop

hearty laurel
#

yeah that could work.. ill play with it and see what I get to, these all sound like good ideas though

hearty laurel
# sonic folio Well one way to simplify this a lot is with binary sensors and a group Add your ...

So, I liked the idea of using binary sensors and groupings. So, I've simplified this down quite drastically. I have 3 booleans that set this up.

  1. OfficeMotionToday - It's an input boolean that gets set when theres motion in the office. It gets switched off at 6am every day.
  2. OfficeSitting - This is a template that combines OfficeMotionToday and the current desk position being down, to give a true/false value.
  3. OfficeSittingTooLong - This is an input boolean set from an automation. Essentially its triggering if OfficeSitting has been true for 2 hours.

As OfficeSitting is based on the desk position and OfficeMotionToday it will act as the 2 hour timer. if i raise and lower the desk, OfficeSitting will be toggled and then the 2h timer starts again.

I opted to use the third boolean OfficeSittingTooLong as it makes it easier for me to debug. I will be setting up an automation so that when OfficeSittingTooLong is true, it will start the angry lights script (which I havent written yet).

I think this is a far more resilent way to do it.. and much easier to debug.. so thank you for pointing me in the direction of binary sensors and groups. I do need to add in the time of day stuff, but, I think it will be fair easier to work with like this

hearty laurel
#

For the 8am - 5pm, I've just set the OfficeSittingTooLong automation to not trigger unless its in the times I am happy with.

For the script, I've opted for two automations, one starts the script and one stops it. They're both triggered from OfficeSittingTooLong being changed. The stop script will also set the scene back to normal.. just so that if it aborts during the "angry" phase. It will go back to normal.

I am sure there will be some caveats to this setup.. so I imagine ill be debugging a little bit still. however, as the whole thing is based off of the booleans, it should be quite easy to debug and work out where it went wrong.