Can math be done on TIME variables (well, DATETIME variables with no date) or only on NUMBER variables?
I want to use a calculated time as a rule trigger to start a heating cycle.
I have two time hub variables. One for the desired morning wake-up time and one for the heat-start time. The wake-up time variable is set by a rule that uses day of the week, holiday calendar, etc. The heat-start time is some number of minutes before the wake-up time. That number of minutes is set by rule as a local variable of number type called pre-heat minutes. It depends on the predicted outside temperature. I want to set the heat-start time to be the wake-up time minus the pre-heat minutes. These calculations are done at 1:00 AM for the upcoming day.
Then I use the heat-start time as the trigger for a rule that will start the heating cycle.
Is this possible with DATETIME variables? Or do I have to use all NUMBER variables and epochtime and such (which sounds like a bit of a pain)?
Bonus points -> Is there an easier way to trigger a rule based on a calculation between two variables? I'm just assuming I have to establish the desired time in a hub variable so that I can use it to trigger the rule. If there is a better way, I'm all ears.
Thanks in advance!
1 Like
Thanks! It's not all set up yet. I'm testing the components ahead of time to see what issues I run into (like this one). But here's some of what I've got:
I have a series of hub variables set up to capture the times when thermostat setpoints will change. Here are a few:
Then I've got a 'setup' rule that will run at 1AM and will determine the times I want the setpoints to change and load them into the hub variables (eventually, it'll also calculate the setpoints which will go to another set of hub variables). Here's what I have on that:
There's a bunch in there that is immaterial to my question and still in a simplified version, but it gives an idea of what I am up to. The spot I'm at now is at the bottom. I've got the hub variable (Time) for Morning time set. I've got the local variable (Number) for PreHeat duration set. I want to see the hub variable (Time) for Pre-Morning to be the Morning Time less the PreHeat duration.
Then, I'll use that Pre-Morning time as a trigger to another rule that actually adjusts the thermostat setpoints. It'll look something like:
So I'm stuck at the bottom of the setup rule in trying to put a usable time into the Pre-Morning Time hub variable. I guess I can go figure out epoch times and do it all with number variables. I haven't messed with that for a while. Then I suppose I'll need to convert it to a time somehow to make the trigger work. Not sure on that yet, either.
What is this "Set Event" thing you are showing in your image? That kinda looks like it is subtracting 45 minutes from a time. and it doesn't look like epoch time (is it?).
Thanks for looking at this!
Ok. I think I see it. You set the variable to a variable with a variable offset. It looks like the offset is always added and is always minutes, but I can make that work. Thanks for pointing me in the right direction!
I do have Thermostat Scheduler working now. This is meant to be an improvement on that. Mainly because I want all the Period times and the heat & cool setpoints and even the fan mode to be variable. This way I can adjust them based on information from a calendar (indicating work days vs non-work days), presence (different people like different temps), outside conditions (pre-heats take longer when it's cold out; we like it warmer inside when it's colder outside), and who knows what else. If there were a way to use a rule to update the times & setpoints in the Thermostat Scheduler (I didn't see a built-in means to do this), I might do that instead of commanding the thermostat - but the calculations would remain the same. Likewise, I could probably use my time triggers to change the Mode via Mode Manager and have that control the Thermostat Scheduler, but that wouldn't help me with setpoints and fan mode and such.
This isn't even all of the master plan. I also need my away mode to be triggered not just from presence, but from when windows are open. Plus hooking up booster fans in the registers of rooms that are distant from the thermostat and using a z-wave switch to turn them on when their room's temp differs too much from the stat, boosting their airflow and catching them up. I also have an in-line humidifier which I will put a relay in front of it and operate according to indoor sensor readings and outdoor temp. So, lots to do. Starting small.
1 Like
Ok - interesting. I don't know why I didn't see that. I would kinda rather use Thermostat Scheduler. It would replace a set of rules that trigger on time for each of my periods (of which there are up to 10, depending on the season!).
But at first glance, I'm not seeing it. I tried to make a rule to change the time of one of the Periods in my Thermostat Scheduler. I'm not seeing a command to do that. I would be stuck with only the pre-programmed times for each period. Then I looked for how to change a setpoint. I see that I can change which of the day-groupings I want to use (and they might have different setpoints), but I don't see how to actually update a setpoint with a calculated value.
I really only glanced at it, though, so I'm likely missing something important. I'll spend some time with it and see what I can make it do. It's still a good idea and worth trying. If not, having 10 more Rule Machine rules won't break the bank, I suppose.
Thanks a ton for your help! I love that this community likes to dig into obscure use-cases!
1 Like
It all seems possible so far...
Ok. So say I have a Thermostat Scheduler set up with a Period of 'Pre-Morning' (I don't right now, so I don't have a screenshot - but roll with it). And say that the time for Pre-Morning to start is currently 6:00AM and that the heat setpoint will be 68 at that time. Let's just talk time and heat setpoint for now, to keep things simple.
I run the calc in that rule posted above. I added some to the end that looks like this:
You can see that the rule (run shortly after midnight) determines the 'Offset PreHeat' to be -40. This comes from a default and is modified by the outside temperature. That goes into the setting of the 'Time 1a Pre-Morning' variable by being added to the 'Time 1c Morning' variable (which is 6:30AM). Basically, this means I want the start the Pre-Morning period 40 minutes before the Morning period (ie - turn on the heat 40 mins before getting up). So it will set the Pre-Morning time variable to 5:50AM.
I want to update the Thermostat Scheduler so that the Pre-Morning period will be changed from what it was yesterday (6:00AM) to what I want it to be for today (5:50AM). Thus, my heat will come on 10 minutes sooner today than it did yesterday.
How would I change the time for the Pre-Morning period in the Thermostat Scheduler from 6:00AM to 5:50AM?
Ok, thanks! I can play with that.
And I will almost certainly put it all together into one rule and reduce the global variables - I didn't want that many in the first place. The idea would be that the rule runs once a day and collects the necessary data from calendars, weather service, calculated rates of heat/cool from previous days, etc; calculates the times, setpoints, and modes; and updates the schedule. Still much to do to get that together.
It'll be a while before I have this up and running, but I think you've given me the means to do most of it. Thanks for the assist!