Using duration of a rule or trigger in an expression
-
Hi, I have a rule that I have been using in the Vera version of Reactor for a number of years and I am trying to recreate it in MSR and need some advice. The rule monitors the state of our garage door and sends a regular alert if the door has been open for a period of time. The alert contains a variable/expression that provides the duration in minutes the door has been open - eg the end notification looks like this: "The door has been open for X minutes"
I have everything working OK in MSR except for constructing the expression to provide the duration the door has been open. In Reactor I was using the 'getstate' function in an expression to get the runtime of the rule and then converting that to minutes and passing it to the notify action.
In MSR I can't work out how to get any info from a rule within an expression.
The trigger is a simple pulse every X minutes so I was hoping it would be possible to just get the duration of either the rule or the time the door has been open. In the documentation there is a lot of info on getting details of entities, but I couldn't find anything on getting the status of the rules within MSR as it doesn't look like they show up as entities? I hope I didn't miss that part of the doco.
I did a bit of searching but couldn't find any discussion on getting this type of info so I'm hoping someone will be able to point me in the right direction.
I'm using build 22179 on Docker and the devices are currently in Vera but I am likely to move them to HASS at some point.
-
Hi, I have a rule that I have been using in the Vera version of Reactor for a number of years and I am trying to recreate it in MSR and need some advice. The rule monitors the state of our garage door and sends a regular alert if the door has been open for a period of time. The alert contains a variable/expression that provides the duration in minutes the door has been open - eg the end notification looks like this: "The door has been open for X minutes"
I have everything working OK in MSR except for constructing the expression to provide the duration the door has been open. In Reactor I was using the 'getstate' function in an expression to get the runtime of the rule and then converting that to minutes and passing it to the notify action.
In MSR I can't work out how to get any info from a rule within an expression.
The trigger is a simple pulse every X minutes so I was hoping it would be possible to just get the duration of either the rule or the time the door has been open. In the documentation there is a lot of info on getting details of entities, but I couldn't find anything on getting the status of the rules within MSR as it doesn't look like they show up as entities? I hope I didn't miss that part of the doco.
I did a bit of searching but couldn't find any discussion on getting this type of info so I'm hoping someone will be able to point me in the right direction.
I'm using build 22179 on Docker and the devices are currently in Vera but I am likely to move them to HASS at some point.
@d868 said in Using duration of a rule or trigger in an expression:
The door has been open for
Well, if I understand the scenario correctly, I imagine that you must have some sensor that indicates when the door is opened, a contact sensor.
I would put a rule that when this sensor is {true}, door open, I would save in a global variable:
Set Variable varOPEN = ${{ [time(),0,0,0] }}
Then when the alert is executed from time to time, update the variable with the:
Set Variable varOPEN = ${{[varOPEN[0], floor((time()-varOPEN[0])/86400000), floor(((time()-varOPEN[0]) % 86400000)/3600000), floor(((time()-varOPEN[0]) % 3600000)/60000)] }}
And you would get the message like this:
${{ format( "The door has been open for: {}d {}h {}m", varOPEN[1], varOPEN[2], varOPEN[3]) }}
varOPEN would be an array, which in the first position has the date and time when the door was opened, then in the other positions I put days, hours and minutes.
I hope I have helped.
-
Some good ideas here. Some thoughts... pardon my brevity, still on vacation with very poor Internet.
- Use a local variable in the rule, not global
- Store just
time()
directly there's no need for a complicated array and the complicated expressions needed to set and manage it. - In the Set reaction for the rule, use a repeat group with a delay inside to send the alert.
- Make sure the Reset reaction contains at least one action (a comment is enough) to ensure that the Set reaction is stopped when the door is closed.
- Use
strftime()
to format the time saved in the local variable. Simple math subtracting the saved time from the current time will give you the duration of open.
Back to my regular keyboard in a couple of days
-
Some good ideas here. Some thoughts... pardon my brevity, still on vacation with very poor Internet.
- Use a local variable in the rule, not global
- Store just
time()
directly there's no need for a complicated array and the complicated expressions needed to set and manage it. - In the Set reaction for the rule, use a repeat group with a delay inside to send the alert.
- Make sure the Reset reaction contains at least one action (a comment is enough) to ensure that the Set reaction is stopped when the door is closed.
- Use
strftime()
to format the time saved in the local variable. Simple math subtracting the saved time from the current time will give you the duration of open.
Back to my regular keyboard in a couple of days
@toggledbits YOU ARE ON VACATION! Forget the community
As always, great commentary.
I copied something that I am already using, and I ended up using a verifiable global because I use the information in several rules, so by the global, I can share the values.
Use an array because the rules I mention are triggered by intervals, like 20 days, or 12 hours. So I have a routine that every 33 minutes updates several variables that I have in the system, like their times, and then the action can happen by validating what is in the array.
Now, if it is for single control, it is possible to make things simpler and more direct as you mention.
Thanks.