RM - Check for temperature rate of increase over threshold

Hi everyone!

I am trying to turn on the towel and mirror warmers in my bathroom when the temp sensor I have mounted on the hot water feed line gets hot.

I could, of course, set a simple threshold to pass to trigger the event, such as:

if [measured temp] > 100F, then trigger my event

But the problem with this is, for it to be triggered a SECOND time, the temp sensor has to cool back down under 100F degrees. What if it gets all the way up to 120, then slowly cools to 105, then a second person starts a shower, and it shoots back up to 120? It wouldn't trigger a simple rule like above.

So really, I'd like a rule that says:

if [measured temp] has increased at a rate of at least 10 degrees per minute since the last measurement, then trigger my event.

The rate at which new temp events come in is not consistent. They can come in as fast as every few seconds, while the temp is changing.

So, as a programmer, the logic I anticipate here is:

[set tempVal variable to 0]
[set tempTime variable to 00:00:00]

  • new temp event comes in.
  • subtract the tempTime value from the current dateTime value, returning the number of seconds since the last measurement (let's say we put this value in a var secondsSinceLastMeasurement)
  • subtract the tempVal value from the current temperature value, returning how many degrees the temperature has increased (let's say we put this value in a var tempChangeSinceLastMeasurement).
  • divide tempChangeSinceLastMeasurement by secondsSinceLastMeasurement, giving us degrees per second of temperature increase since last measurement
  • Simple logic saying "if degrees per second of temperature increase since last measurement > 0.3", trigger my event. This value can be adjusted as necessary.
  • save the temperature value to var tempVal, save the current datetime (down to the second) to var tempTime so it's ready for the next event.

Am I overthinking this?

It's not clear how you actually have this set up, but with a "regular" trigger event:

Sensor X temperature > 100 F

then you would get a "match" (trigger event) every time the sensor sends a reading that is over 100 degrees--regardless of what the previous reading was. So, the problem you state would not actually be a problem. Therefore, I'm wondering how you actually have this configured. If you use a required expression of "temperature <= 100" and a trigger event of "temperature > 100," then, yes, it would need to go back down before it could trigger again--that's one of the things required expressions are useful for capturing.

So, I'd probably think about that before thinking about the rest of your post. If you do need to go that route instead, I'm thinking you could calculate rate of change and store it in a local variable, though it might be easiest to break that part into a separate rule and then just trigger this one based off of something from that. There isn't anything built-in for rate of change, so you'd definitely need to calculate it yourself somehow, but it shouldn't be impossible.

But if the "problem" above isn't a problem at all, then things are a lot easier. :slight_smile:

You're right, I forgot to include one detail - I am starting a 60 minute timer when the event is triggered.

I don't want to trigger it every time the temperature is measured over the threshold, because if it takes 30 minutes for the water pipe to slowly cool back under it, it'll be re-setting the timer to 60 minutes every time a measurement is read, until it's under the threshold - resulting in a (variable) ~90 minute timer instead. Thus, I want to trigger this ONLY as long as the temperature is actually increasing - so the 60 minute timer will be "counting down" once the water temp stops increasing (which will occur within a minute of when a person starts running a bath or shower) NOT once it has cooled below a threshold (which may take 30 minutes, as mentioned).

The way I'm doing it now is:

However, this is a little bit janky because it doesn't know how long it's been since the last reading. Hypothetically, if readings are coming in every second, it's unlikely to ever trigger because the temp won't increase by more than 3 degrees between readings. But at least it only triggers the event (turn on the "Master Bathroom Accessories") if the temp is increasing by at least 3 degrees between readings.

You could use a Periodic trigger (every minute) and compare IF temp-now > temp-stored + 10 THEN run actions. Using a private boolean would prevent multiple triggers if that is a concern, but it seems like you wouldn't need it. If you have any other "smart" components in the bathroom (lights, motion, etc.) you could use those as predicates to make sure you're only triggering the rule when the bathroom is occupied. That might not be necessary either.