Page 1 of 1
lastUpdate.minutesAgo for security state - how?
Posted: Tuesday 09 October 2018 11:41
by funnybu
Hello. I need get lastUpdate.minutesAgo (or hoursAgo) for security state.
For example i need switch boiler to standby mode if my Dz had "Armed Away" state more than 2 days...
Re: lastUpdate.minutesAgo for security state - how?
Posted: Tuesday 09 October 2018 23:20
by waaren
funnybu wrote: ↑Tuesday 09 October 2018 11:41
Hello. I need get lastUpdate.minutesAgo (or hoursAgo) for security state.
For example i need switch boiler to standby mode if my Dz had "Armed Away" state more than 2 days...
The field lastUpdate does not exist for the Domoticz Security Panel in dzVents. The workaround for this could be a script like
Code: Select all
-- security.lua
return {
on = { security = { domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEDHOME,
domoticz.SECURITY_DISARMED },
timer = {"every 10 minutes" },
},
data = { securityState = { history = true, maxItems = 1 }},
logging = { level = domoticz.LOG_DEBUG,
marker = "Security" },
execute = function(dz, item )
if dz.data.securityState.get(1) == nil then
dz.data.securityState.add("Initialized") -- Initialize persistent historical variable (= data + timestamp)
dz.log(item.trigger,dz.LOG_DEBUG)
end
if item.isSecurity then
dz.data.securityState.add(item.trigger) -- Store state to persistent historical variable (= data + timestamp)
else
safedSecurityState = dz.data.securityState.get(1)
dz.log("Security state set to: " .. safedSecurityState.data .. ", " ..
safedSecurityState.time.secondsAgo .." seconds ago.",dz.LOG_DEBUG) -- retrieve state and set time secondsAgo
end
end
}
Re: lastUpdate.minutesAgo for security state - how?
Posted: Wednesday 10 October 2018 9:03
by funnybu
May be easiest way write user variable? (and read it from another scripts) I think it is possible do with dzvents and more universal. What do you think?
Re: lastUpdate.minutesAgo for security state - how?
Posted: Wednesday 10 October 2018 12:35
by waaren
funnybu wrote: ↑Wednesday 10 October 2018 9:03
May be easiest way write user variable? (and read it from another scripts) I think it is possible do with dzvents and more universal. What do you think?
Yes, good idea ! Write the uservariable with my script and read it with other (your) scripts. Let me know if you cannot get it working.
Re: lastUpdate.minutesAgo for security state - how? [Solved]
Posted: Thursday 11 October 2018 7:48
by waaren
funnybu wrote: ↑Wednesday 10 October 2018 9:03
May be easiest way write user variable? (and read it from another scripts) I think it is possible do with dzvents and more universal. What do you think?
Like this ?
Set
Code: Select all
--[[ setSecurityState.lua
Before first execution of this script, the vars "SecurityStateModifyTime" and "SecurityState" need to be created as type string.
values can be left empty
]]--
return {
on = { security = { domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEDHOME,
domoticz.SECURITY_DISARMED },
},
logging = { level = domoticz.LOG_DEBUG,
marker = "setSecurityState" },
execute = function(dz,item)
local securityState = dz.variables("SecurityState")
local securityStateTime = dz.variables("SecurityStateModifyTime")
local function setVars(str)
if securityState.value ~= str then
securityState.set(str)
securityStateTime.set(dz.time.raw)
end
end
setVars(item.trigger)
end
}
Get
Code: Select all
--[[ getSecurityState.lua
this is a script to demonstrate how to get the states from the security panel and lastupdate time of this state.
The update of the variables is done by the setSecurityState script and that script must have run at least once before this one
]]--
return {
on = { devices = { "securityTrigger" }}, -- Just for test purposes.
execute = function(dz)
local securityState = dz.variables("SecurityState")
local securityStateTime = dz.variables("SecurityStateModifyTime")
-- Get securityState and time set
local Time = require('Time')
local t = Time(securityStateTime.value)
dz.log("Security state set to: " .. securityState.value .. ", " ..
t.secondsAgo .." seconds ago.") -- retrieve state and set time secondsAgo
end
}