Probably a stupid question, but I have not been able to find how to set a global variable to a Date/Time. I am trying to record the last active date/time of a motion sensor in order to determine how long since someone has been in the room in order to add additional logic to my "Night-time" mode transitions. My plan is to set a global variable to "Now()" (pulling from my VBA days) and then using it to compare to later. The gv type is string.
How do I do this....or is there a BETTER way to do it?
You can only do that using the time in seconds or the time in milliseconds. You should see both of those options in setting a global variable.
However, how are you going to trigger a rule in RM 4.0 based on that? Continually checking over and over if this threshold has been breached is very inefficent for the hub. The hub is not a state machine, it's event based. You are trying to set to night mode based on what? no one moving around for a period of time? That isn't the most useful function in my experience. It takes too long to trip and lights stay on far too long. But the same would be possible triggering just off the motion sensors all going inactive for a period of time. You could do this:
Triggers: Any of a list of motion sensors changing
Actions:
If list of sensors any active
Cancel delayed actions
Else if All sensors inactive
Delay actions for X minutes
Execute your nighttime routine
End-If
I have a rule to check the time once a minute. For exactly the same reason: to check if a time in seconds stored in a GV has been reached.
I use it to trigger if a room has been vacant for a given time period. The GV gets a new value of current time plus 5/20/45 minutes on motion depending on current modes of Active, Occupied , and Camped.
I was entirely inspired by the rooms occupancy app. With RM4.0 I get the same basic functions without all the extras the author built in.
That's sounds terribly inefficent to me. It would be easier if you had a driver that you scheduled via a cron job or something like that rather than running a rule very minute. Hubitat is Event bases....it should be responding to things changing. Not checking states every minute.
I stumbled here while trying to do something similar - setup a rule to turn on a light based on motion and leave the light on for 15 minutes... unless there's continued motion, in which case basically "reset the countdown timer to 15 minutes." I wonder what you ended up with @michael.l.nelson and if you're happy with it?
There are many ways to do this. First suggestion is to not use RM for it at all, but rather either Basic Rule or Room Lights. Both of these have exactly the feature you are asking for.
If you need to use RM for some other reason, you could do this:
Love it! I see your example, that's awesome and thank you. I also see how do do what I want with Basic Rules, which I hadn't thought of. I also really like Room Lights, which I didn't know about until now, however I hvae a follow up question: what's the right way to handle a door contact sensor that's between two rooms? I want it to automate things on both sides yet I seem to have to assign each device to a specific room only and, as far as I can tell, Room Lights only let's me use the devices in the room as inputs... thoughts?
You can select devices by two methods in Room Lights: by selecting a room (on the left), or simply by selecting devices (on the right). You are not limited to the devices in a room.
My bathroom lights are using the new Room Lighting app. The rooms that I wanted to use with variables are on an entirely too complex set of Rule Machine rules. I have seven RM rules per room plus dashboards and button controllers. I'm following a programmer's rule; if it works, don't touch it. Definitely use Basic or Room lights where you can. Much simpler to trouble shoot than RM.