Setting a start time based on expressions

I got a wild idea and am working through the logic on it, but I believe it has reached the limit of my knowledge. I searched for something similar, and LuaXP may be the solution, but again, at the limits of my knowledge.

A little backstory on the idea. I have a cabin in the mountains and it takes a little while to heat up. A couple of times I’ve forgotten to turn on the thermostat. I remembered part way there, but the temp was still in the low 50’s upon arrival. And if I totally forgot, it can be 33*. What I was thinking about doing was setting up Reactor with a time that I am planning on arriving and then having the expressions do the reverse math to determine at what time the heater should come on so that it is warm before I get there.

Using the above expressions as my sample. I am estimating arriving at (ArrivalTime). Based on the current temperature, I need to warm the place up (DeltaTemp) degrees so it will be 63*. My furnace heats the place 6* per hour and I would like it to be up to 63* two hours before I arrive. So I need to heat for (HeatTime) hours. The (StartHeating) is where I start to get above my knowledge. Since this is not a time format. Somewhere before 2:00 is when I need to start heating.

And the final piece/question. Can the final time format output be used in a condition? I/E: I plan to arrive on Jan 28th and need to start warming the place at (StartHeating).

I know I know. A lot of effort, but we’re HA geeks and why not?

We did this a lot when I worked in building automation. Given an occupancy time and outside air temp calculate when to start the system to get the space comfortable by the occ time. The routine was self-correcting and had a different factor for different ranges of OSA temp. I even used it once on an Olympic size swimming pool and it worked great after a bit of tweaking.
The system I programmed was the thermostat and we had to allow for things like starting a boiler an hour before the first building started to insure steam was available for heating.
I don’t have the skills to do this with Vera but the concept is certainly not a new one.

OK, so first thing, you don’t need to use getstate() to get the value of variables that are in other expressions in the same ReactorSensor. You can just say, for example, HeatTime = (DeltaTemp / 6) + 2. If you’ve exported those variables that currently are the targets of getstate() in these expressions, that is also not necessary.

In order for this to really work out, you need ArrivalTime to be an actual date/time. You can do that with this expression: date( 2021, 01, 30, 08, 00 ). This sets not just a time, but a specific date (Jan 30 2021 in this example) on which you will arrive, which eliminates a problem I’ll describe later. The result of this expression will be a Unix Epoch time (time in seconds since midnightZ Jan 1 1970).

From there, you can easily compute the full date/time when heating should start: StartHeating = ArrivalTime - ( DeltaTemp / 6 + 2 ) * 3600. We have to multiply by 3600 because your units are hours, but timestamps are seconds (so 3600 seconds per hour applied).

Then an expression to see if it’s time yet: TimeToStart = time() >= StartHeating. This checks the current time against the computed heating start time, and if it’s passed, the expression result is true.

Now, in your ReactorSensor’s conditions, you make two groups:

  • Group “Start Heating”
    • Condition: Expression Value, variable “TimeToStart” is TRUE
  • Group “Tick”
    • Condition: Interval every 300 seconds (5 minutes).

The first group is your active group that will make the heater come on when it’s time to start heating. It’s just looking at the “TimeToStart” expression value, and if it’s true, that condition and its parent group will be true as well. The “is TRUE” activity for this group should turn on your heater.

The second group uses an Interval condition that just fires every 5 minutes, and this causes the expressions to be force-evaluated. Reactor does not continuously evaluate expressions that contain time values; you have to make it update. The Interval condition is good for this.

I mentioned earlier that there’s a problem with “hours only” use of ArrivalTime. It doesn’t consider that these conditions will be running continuously, so this logic can potentially fire every day (because date isn’t considered) and cause you heater to come on when you’re not there. Being more specific with that variable by making a full date and time resolves this.

The other thing not resolved in this logic is a way to turn it off and stop insisting the heat be on. Since TimeToStart will be true from the moment the anticipated start time is reached to forever more, you need a way to say “I’m not here any more, stop what you are doing.” You can do that either by disabling this ReactorSensor when you leave the property, or by adding, for example, a DepartureTime variable to hold another date/time when you are expected to leave, and amend the logic of TimeToStart to something like time() >= HeatTime and time() < DepartureTime. That’s just one easy way, there are many things you can do, many ways to approach it, it just depends on the semantics that work best for the way you use the property and want the heat to perform.

I would also caution you that you would be well-advised to build in additional safeties if you are controlling your heat by automated controls like this. There are dangers aplenty with running heating systems unsupervised, and given the natural instability of the Vera platform and the “nothing guaranteed” nature of ZWave and other subsystems, there are lots of opportunities for failures that could range in consequences from heating an empty house to an unexpected cold arrival to being greeted by a pile of ashes that was the building. Caveat user; the risk is entirely yours.


Thank you @rigpapa for the help with the logic. And a huge thank you for Reactor too.

You are correct, that there needs to be a way to set the TimeToStart expression to false. Probably the simplest I can think would be to add a step to the Activity to change the ArrivalTime to something in the year 2050 or later. But like you said, there are many ways to accomplish this.

And yes, there are risks that come with this. I’ll have to put a lot of thought into this to make sure I’ve covered all my bases. I guess for now, when TimeToStart is true, I can have it send me a notification to manually turn the heat on.

1 Like

Thanks again. For now, I’ve set the group Turn the Nest on Activity to notify me it’s time to turn the heat up. And based on the 5 minute interval, it will nag me until the Thermostat is no longer in the “Off” setting.

Best Home Automation shopping experience. Shop at getvera!

© 2021 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules