[Solved] How do I reset the "Time Since Event"

Time Since Event: contact(open) on LeftSwivel(71:36:01) exceeds 0:30:00 TRUE

In the condition above, the amount of time in the "Time Since Event" only gets reset if the contact is opened and again closed. I would like to be able to reset it within the rule, so that it always gets to check if the contact was opened recently, rather than several days back. In fact, this particular contact was closed soon after the 30 minutes elapsed, but the variable never seems to get reset.

Am I doing something wrong or is there a way to fix this?
Thanks

That's not wrong; "time since event" will show you the time since the last event, which would indeed be contact opened or contact closed if you choose "contact" as the attribute. So, nothing to fix there, and no way to reset it outside of an actual event. (If it's a virtual sensor and the events won't trigger something else or otherwise mess anything up for you, that's actually one thing you can do, again only if these restraints are not a problem.)

However, there is probably some way to do the automation you want, perhaps with a different feature or by approaching it differently somehow. If you share more information about what you are trying to do overall or a screenshot or description of your current rule and the desired outcome, someone will probably be able to help.

1 Like

Hmm - I did upload a screenshot, but it did not show up.

What I am trying to do is something along the lines of this -
IF SensorA is open
notify me
IF SensorB has been open for > 30 minutes
notify me
ENDIF
ENDIF

What I see as a problem is that > 30 minutes does not get reset unless I force it to reset by either opening + closing SensorB or closing + opening SensorB.

That is why I was trying to reset it.
Looking through past comments I see that the Rule Machine is not completely stable, so I guess I should not expect too much from it.

Any suggestions are welcome, and if there are none, then I'll just abandon the complex rules and fall back to the more simple but less useful IF this then that END type rules

What are you actually trying to do? I understand the pseudo code, but it's not clear if that's what you have or a precise RM summary of what you really want -- in which case it doesn't mean anything without trigger events and might not do what you want, and the IFs may or may not be what you want since they are evaluated at the moment reached and also nested inside each other, so that second one won't be reached unless the first is true (either could be what you want, but it's not clear).

In other words: I guess I'd suggest a plain English description of the automation instead and we can start from there. :smiley:

ex-programmer so easier for me to think in pseudo-code :slight_smile:

when SensorA is open it should notify me, then check if SensorB has been opened for more than 30 minutes and notify me if it has been. If SensorA is not open then do nothing.

Thing is the way it currently works is that when SensorA gets opened, SensorB always appears true, since the "Time Since Event" keeps accumulating. That variable does not get reset unless an open/close event is forced on SensorB.

Or maybe I am just understanding the use of this variable all wrong

Rule 1
Required expression : private boolean true
Trigger: Sensor A open
Action: Your actions - notify etc

Rule 2
Trigger: sensor b open and stays 30 minutes
Action: Set private Boolean of rule 1 true, wait for event sensor b closes, set private Boolean of rule 1 false

Just thinking/typing out loud but will that work for you?

I would expect it to get a similar response - SensorB always show up as being open for > 30 minutes, since the variable used to test the duration does not get reset without a manual intervention

Flip it around

Just to make sure I understand: are you trying to check how long it's been since the last opened/closed event was on Sensor B? That's what your rule should do. If not, what do you actually want to check if not the time since an event for this attribute -- which is, well, what "Time Since Event" will do? It sounds like some sort of manual reset, but how would that be initiated? If this rule triggering, that won't work (it's going to be evaluated more or less immediately after triggering if it's even reached, so: false); if some other event, then a hub variable, virtual device, or some other workaround might be more appropriate.

Once B has been open for 30 minutes, it sets the PB in rule 1 allowing it to trigger and so when sensor A opens it will notify you. As soon as sensor B closes the PB in rule 1 goes false and opening sensor A will do nothing. Opening B again will do nothing until it’s been open 30 minutes.

Robert - I was attempting to see how long SensorB has been currently opened - not how long it has been open since the last event. I think I was erroneously expecting the internal variable "TIme Since Event" would get reset by the system at end-of-day, or something similar.

Thanks Robert & John - let me play around with Johns suggestions.
I will also look into whether the "AND Stays"... option offers me an better alternative

Devices keep a history of events (you can set the history size in the device details page). Time since event looks up that history. Nothing is reset - but older events roll off as new events come in.

I believe you can achieve what you want with a single conditional trigger. First create a Time since event condition for your switch B. Then create a trigger for switch A and flip on “Conditional trigger?” and select that condition.

1 Like

Thank you - I'll add your suggestion to the things I will try

I think I know what piece you might have been missing using Time since event. Searching for the last "on" event doesn't tell you that the switch is actually currently "on" - there could have been a subsequent "off" event. Here's how to put it all together (using 30 seconds for the purpose of this test) :

1 Like

Thank you - this looks very interesting and promising! :slight_smile:

I'll be able to get time to check it out only after a couple of weeks at best, so please do not await a faster response.

I was foolish and created a problem where none existed.
The sensor "Time Since Event" state does reset to zero when the contact sensor is opened, so this rule works correctly -
IF (SensorA contact open(F) [FALSE]) THEN
IF (SensorB contact open(F) [FALSE]) THEN
Notify Me: 'Both Sensors are open'
IF (Time Since Event: contact(open) on SensorB(1:16:32) exceeds 0:30:00(T) [TRUE]) THEN
Notify Me: 'SensorB has been open for 30 minutes'
END-IF
END-IF
END-IF

"Time Since Event" does not reset until an event occurs, so if both the conditions are not True for a looooong time, I have no idea what happens to Hubitat - does it get an overflow condition? How will it handle that?

Aside from those questions, this post can be closed.

Thank you everyone for all your suggestions