I'm trying to record the last time a motion sensor was triggered. The Time global variable doesn't seem to be able to do that when I try the set it in RM.
Is there a way to record time in Rule Machine, or do I need to write in Groovy ?
Edit: I want to use the time value to compare it in other automations
If you want a certain fixed time interval, then perhaps you may want to look at the "switch timer with reset". This virtual device can be set to be on in RM, and will go off automatically after N minutes (or seconds). With this virtual device, you can check in RM to see if this switch is still on, and then you know that the motion happened in the last N minutes (or seconds).
This is a simple, but somewhat clunky way of handling the "time since something happened" issue.
Thanks, I'll take a look at it. I know this is not so simple since looking at the forums, lots and lots of people would like this feature but I never found a solution. It would be great for security for knowing a room's last occupation. Or when someone used a room
In general this is not the preferred method to perform this function, simply because you have to constantly comparing this variable to another. Performing an action after a delay period that is initiated when the sensor becomes inactive. You don't want to do that based on the sensor going active because there's no way of knowing how long the sensor will be active.
What type of automation are you planning on using this data for? This can be captured in a regular number variable in epoch format. Depending on what you want to use it for, that could be more useful than using a date/time variable.
First use would be to show on dashboard for information/security
Second would be for scenes depending on how long the room has not been used. I understand Hubitat and home automation in general is event based and the last thing I want is to overload the hub but I can think of a lot a control sequences that could use information stored in a variable, for example seldom used rooms were it can take days for one to be used. On trigger, the app would compare to time/date to something, so it's still event based and should not impair the hub.
I don't mind storing this information as text, and when needed, parse the information back into an app friendly variable.
I'm from the commercial side of automation (27 years) , everything is always scanned to the millisecond, even the apps. We have events too but it's just a different way to program.
Why would it matter when the room was used last? I'm still not understanding what you are using that for so I can't help you implement it. Sorry.
For every device on a dashboard, you can access a history via the 3 button menu on the device tile. This will show a list of the history of the events for the device. Would this be of any help for displaying the information you are looking for?
@yannick00000 I am one of the people that has asked on this forum for a way to do see the last time motion was triggered. I want to be able to look at all of my sensors on a single dashboard and see when they were last activated. Clicking on the 3-button menu is not an efficient way to achieve that. The other problem is that motion sensor will typically also report their temperature and battery status and those reports are not the last time that the motion sensor reported motion but the last time the sensor reported something. I haven't found a good way to do it yet.
Maybe I'm looking at this the wrong way. I'm used to having trends or some sort of history application built-in that records every event in the system. Hubitat does'nt have that (I know some use applications like Grafana but I'm not there yet. Well, you could say that Hubitat logs is something but there is no recording and I don't think apps can use any of it.
I was looking for some way to trigger event based on how many motion detects have triggered in such amount of time. Exemple: I'm going to install 4 outdoor motion sensors around the house to know if someone is in the backyard. Outdoor motion detectors are prone to false alarms so I would use the time stamp to figure how many MD have triggered in X amount of time.
I could probably do this using Cancel delays and such in RM. But why is this so hard to do ? It seams easy to just copy time date in a variable. Basic stuff, no ?
@bptworld Bryan do you have an app that would do this? They want to display the last time motion was active/inactive on a dashboard. I know you have a ton of apps that serve this sort of purpose.
Take a look at the zone motion built in app. It has all of the functions necessary to do this built in. You can specify the number of sensors that must go off in order for the virtual sensor to go active and within how much time. You don't have to do all of the coding for this (and you wouldn't want to) in rule machine. It's already built in for you.