Hi,
I tried to find the answer, but…
I need to know how long one device is on.
10x
bore
In what form do you want this information? Some options are: Global Lua variable; VariableContainer variable; Condition in PLEG; Text file in Vera file system. What resolution do you want (days, hours, minutes, seconds)?
Two additional app to add to Rex’s list are datamine and event watcher.
Or if you’re simply looking for the last time that “something” last changed, and if that something is represented in a Device State Variable somewhere, then in Lua this is simply:
local x, t = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 11)
luup.log("XXXXXXXX: Status variable on device 11 last changed:" .. t)
luup.log("XXXXXXXX: Changed (secs):" .. (os.time() - t))
The variable “t” will be in epoch time, as is everything, so you’ll need to form it into whatever shape you really need it in. In your case, you can just subtract it from os.time() and it’ll tell you how long it’s been in that state.
In this case, it’s the light switch in my offfice (Device 11), which I pressed on a few moments ago.
Each time a Luup Variable is changed, there’s a corresponding timestamp behind it that’s set at the same time.
What’s with the Tex, Bruce? ;D
What’s with the Tex, Bruce? ;D[/quote]
Damn mobile auto spell checker and auto correction.
oh too early in the morning…
Regards
Bruce
VariableContainer and working hours are ok for me.
I want to know how long my heat is on in one day, month, year…
I have datamine and I can see status change, but how to sum time with the status 1…
10x
Create a scene with a schedule to run every, say, fifteen minutes. Also add a trigger to run the scene when your switch (dID) is turned on. Paste this code into the Luup tab. Change dID, vID and vNo as required.
local dID = 68 -- Device ID of your switch
local vID = 76 -- Device ID of your VariableContainer
local vNo = 5 -- Variable number (1-5) for result
local status, tOn = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
if status == "1" then
local tNow = os.time()
local tRun = (tNow - tOn) / 3600
local hRun = string.format("%02.1f Hours",tRun)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable" .. vNo,hRun,vID)
end
When the switch (dID) is on, the VC variable will show the number of hours (n.n Hours) it has been on. The run time is cleared to zero whenever the switch is turned on.
this code is ok and i can use it.
10x
I made some changes and may be the next is better for me:
local dID = 51 – Device ID of your switch
local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,dID)
if status == “1” then
local start = os.time()
VContainer.set(“start”, start)
else
local t = os.time()
local start = VContainer.get(“start”)
local work = VContainer.get(“work”)
local now = (t - start)/60 ----min
local fin = (now + work)
VContainer.set(“work”, fin)
end
2 Variables, 2 triggers, 1 scene.
The only problem is if I accidentally, manually start the scene…
10x