How to automate based on an ever-changing time? #186
-
Context: I have roller shutters on windows that I can automate. Today they go up and down based on a set time (or an offset from sunset). I would like to make them go up based on a time that is reassessed every minute. Details: I retrieve the school start hours of my children from the school site and they are available as MQTT messages, updated every minute or so. I would like to move the shutters up an hour before school starts. The problem: it should be a one-time "up" per day. If someone wants to pull them down I do not want them to go up again just because it is "later than an hour to school". Before I get into a Rube Goldberg machine kind of automation I am asking, in case someone has already thought this out and has a reasonable approach |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Here's one approach. Just trigger off the MQTT message, and the task does a To make this only happen once per day, you'll also have to have a flag (eg, some state variable) that is set when the shades are auto-opened. Once the flag is set, the MQTT task trigger should be disabled by putting that condition in |
Beta Was this translation helpful? Give feedback.
Here's one approach. Just trigger off the MQTT message, and the task does a
task.unique
and then atask.wait_until
until an hour before the school time (or skip if it's already less than an hour). After thetask.wait_until
it opens the shades. Each time you get a new MQTT update, the old task gets killed and replaced by the new one, which uses the potentially new time to do the nexttask.wait_until
.To make this only happen once per day, you'll also have to have a flag (eg, some state variable) that is set when the shades are auto-opened. Once the flag is set, the MQTT task trigger should be disabled by putting that condition in
@state.active
. You can reset the flag each morning with a fi…