Hi
Is there a way to count the time that some device is on ?
I want to trigger a scene that will query that and return to my Vera alerts the answer in minutes.
Thanks
Inmar
Hi
Is there a way to count the time that some device is on ?
I want to trigger a scene that will query that and return to my Vera alerts the answer in minutes.
Thanks
Inmar
Input Device:
Device1On When some device turns on
Device1Time ((#DeviceOn; Device1On) AND !NOW) ? 0 : (NOW AND Device1On ? (#NOW - #Device1ON) : (#!Device1On - #DeviceOn)) / 60
Note this logic resets the time to Zero when the device first turns one … every minute it updates the current on time … when the device turns off it computes the final ON time. On Time is in minutes.
Hi
First thanks for the answer.
I’m new to this technology… so I have some questions…
What is “DeviceOn” ? it’s another input ?
What is On Time
Is this logic works even if the device is still on ?
How can I use the “On time” as parameter inside a message for the vera alert ?
Thanks
Please read the PLEG Getting started guide first … them post any remaining questions.
[quote=“RichardTSchaefer, post:2, topic:180099”]Input Device:
Device1On When some device turns on
Device1Time ((#DeviceOn; Device1On) AND !NOW) ? 0 : (NOW AND Device1On ? (#NOW - #Device1ON) : (#!Device1On - #DeviceOn)) / 60
Note this logic resets the time to Zero when the device first turns one … every minute it updates the current on time … when the device turns off it computes the final ON time. On Time is in minutes.[/quote]
a couple little typos
Try:
((!Device1On; Device1On) AND !NOW) ? 0 : (NOW AND Device1On ? (#NOW - #Device1ON) : (#!Device1On - #Device1On)) / 60
[quote=“inmar32, post:3, topic:180099”]Hi
First thanks for the answer.
I’m new to this technology… so I have some questions…
What is “DeviceOn” ? it’s another input ?
What is On Time
Is this logic works even if the device is still on ?
How can I use the “On time” as parameter inside a message for the vera alert ?
Thanks[/quote]
add the notification in the Advanced tab for the action as attached
Thanks, I did not test …
I am not sure when he would want to get the message … maybe when the device is turned off … That’s the final answer, the rest are intermediate answers.
If he did not need the intermediate answers this could be simplified.
Device1Time Device1On ? 0 : (#!Device1On - #Device1On) / 60
having some fun, if we wanted to
OnTime = math.floor({(Device1Time)} + 0.5)
and send OnTime to send it in a message from PLEG?
You can’t do math.floor in a PLEG expression … folks have been asking for functions … but it’s not supported at this time.
You can do this in the LUA code for the actions:
DEVICE1TIME.state = math.floor(DEVICE1TIME.state + 0.5)
I knew the answer was in Lua but haven’t learned all the syntax yet… works well ![]()
That’s a nice piece. I was looking to add a notification to keep an eye on how long my pool pump is on.
I’m not sure but you remember but you helped me and we came up with starting 3.5 hours after sunrise and turning it off 3.5 hours before sunset… it accommodates the need to extend the filtering hours it in the summer automatically and very nicely.
[quote=“RichardTSchaefer, post:9, topic:180099”]You can’t do math.floor in a PLEG expression … folks have been asking for functions … but it’s not supported at this time.
You can do this in the LUA code for the actions:
DEVICE1TIME.state = math.floor(DEVICE1TIME.state + 0.5)[/quote]
Hi
I put the code “DEVICE1TIME.state = math.floor(DEVICE1TIME.state + 0.5)” in the luup tab
But still got an a unfloor number…
Does the lua code happens automatically with the action ?
Thanks
You are using the name Device1Time for the condition?
Post your status report and we can take a look.
FYI, looking back at mine, I used the Lua math.floor but opted for string format because I wanted decimals to two places…
–PUMP1TIME1.state = math.floor(PUMP1TIME1.state + 0.5) added decimals
PUMP1TIME1.state = tonumber(string.format(“%.2f”, PUMP1TIME1.state))
I never got around to taking the decimal part and converting to minutes…
I do remember having to create a second Condition that did the Lua above and then set the notification. I put this in the condition just below the event to stop the pump. It had problems with the number until i did that. Lua is so darn fast.
note: I had to clarify that sentence
What do you mean status report ?
I attched some photos…
Push this button (see attachment)… you will get a report
But again, I added a Condition following the end of my timer, I attached the conditions I’m using.
Hi
I attached the screen shots of the report.
Thanks a lot for your time.
If you read the documentation you would see your problem:
This has the same behavior as a SCENE Level LUA ... i.e. if it returns false, it stops executing the explicit actions. If it returns nothing or true it will run the explicit actions. The LUA has context (unlike a scene).
For each input Variable name or Condition name xxx you have access to it from LUA as
XXX.state
XXX.seq
XXX.oseq
XXX.seqh
Where XXX is the uppercase of the input or condion name. And XXX.state is the value, XXX.seq is the On timestamp and XXX.oseq is the Off timestamp, and XXX.seqh is a history of the last N on timestamps (max of 10, not saved across restarts, only the most recent one is) XXX.seq should always equal XXX.seqh[1]. The seqh is currently only used internally for the Multi-Trigger checks.
The LUA context is unique for each Plugin. You can share global variables between Actions, but not between PLEG/PLTS devices or Vera Scenes.
Thanks a lot.
I realy did missed the UPPERCASE issue…
Best Home Automation shopping experience. Shop at Ezlo!
© 2026 Ezlo Innovation, All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules