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...
lastUpdate.minutesAgo for security state - how? [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: lastUpdate.minutesAgo for security state - how?
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 10
- Joined: Monday 07 May 2018 14:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9272
- Location: Russia, Novosibirsk
- Contact:
Re: lastUpdate.minutesAgo for security state - how?
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: lastUpdate.minutesAgo for security state - how?
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: lastUpdate.minutesAgo for security state - how? [Solved]
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
}
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest