I have a virtual switch representing my hot boiler switch. I can turn the boiler On or Off using this virtual switch and it can be done with the switch itself (physically) or a dedicated app.
I would like to present the amount of time the switch was On during the day (reset every night) as an indication that there is or isn't enough hot water for the all family to take a shower.
Looking for a way to present a real time timer on the dashboard for how long the switch was on.
Any ideas?
This is possible with Rule Machine and a hub variable (or any method you have to store or display the data, but this is probably the best option).
-
Go to Settings > Hub Variables, click New Variable, type a name (maybe Hot Water On Time), choose Number as the type, and provide 0 as the initial value (or whatever you want).
-
Create a new Rule. Go to Apps, then find Rule Machine in the list (or install it with Add Built-In App if you haven't already). Inside Rule Machine, click Create New Rule.
-
Provide a name for the rule (maybe "Rule 5.1 - Water Heater On Counter"), then click/tap outside the box to continue.
-
Create three local variables in the rule, which will be used to store and calculate the values necessary to add to the hub variable:
-
Start Time variable, type
DateTime
, any initial value (your rule will set it before it's used) -
End Time variable, type
DateTime
, any initial value (your rule will set it before it's used) -
Total Time variable, type
Number
, any initial value (e.g.,0
; your rule will set it before it's used)
-
Start Time variable, type
-
Add a new trigger that responds your switch turning on (capability "Switch," choose your device, and choose "on).
-
Add actions until your Rule looks like the following:
If you aren't sure how to do some of these, here is the configuration for probably the trickiest one, the second-to-last line/action:
(All of those "Set..." lines are the "Set Variable" action, in case that isn't apparent.)
- Hit Done to save your rule. (Optionally, turn on logging like Events and Actions to see what the rule is doing when if you are trying to troubleshoot. "Display Current Values" may be helpful and also affects logs, not just the RM UI.)
First, thank you for the very detailed explanation.
I am familiar with RM but I was blind to option you suggested.
The problem with your solution is that I need to wait for the switch to turn OFF to get the timer updated.
So, I ended up with only 1 hub variable to capture the time the switch was on since last reset.
Used a repeat every 1 minute while the switch is ON and increment the timer by 1 every minute.
An additional rule to reset the timer daily at 05:00 AM.
Two things I am still missing are:
a. will the repeat every 1 minute impact my hub's performance? - I would think not but we'll see.
b. Was not able to display the counted minutes as a clock, that is, 95 minutes should be easier to read as 01:35.
Thanks for your help.
Oh yeah, I forgot the thing about resetting at midnight (or whenever), but that's easy enough! Also didn't think through updates in real time, but your solution should work. One minute shouldn't be too bad, but you can keep an eye on hub stats if you're concerned.
If you do want a human-friendly "X hours, Y minutes" display, I suppose you could make a hub-level string variable, probably a couple more local variables, then use variable math to compute and store the number of hours and (leftover) minutes, then concatenate those into the string and use that for display instead.
Quick question, how did you reset the timer daily?
Thanks, I was trying to do it within the original rule.