thisUpdate? (as opposed to lastUpdate)
Posted: Tuesday 02 June 2020 13:55
A question: inside dzvents' execute( dz, item) where item is a device, the value for device.lastUpdate seems to be that of the previous change to the device. Is it possible to retrieve from inside this trigger the value that lastUpdate will have after the device has changed? i.e. sort of a "thisUpdate"? I'm trying to see in a customEvent trigger if the device has changed since the customEvent was emitted and I'm trying to use the lastUpdate value for this. But the lastUpdate value I pass with the customEvent is always different than that which is on the device when I get the customEvent trigger.
My (dzvents) code so far:
Output from the log (had to filter all other devices' output out):
The last line in the log shows that my customEvent has the value for the 'Off'-event at "2020-06-02 13:41:02.760". I am looking for a way to get the "2020-06-02 13:41:04.057" value for the 'On'-event when the customEvent gets emitted.
2020-06-02 13:41:14.553 Error: dzVents: Error: (3.0.5) CustomEvent, myTestEvent_552_2020-06-02 13:41:02, device myTest is no longer on. : 2020-06-02 13:41:04 <> 2020-06-02 13:41:02.
My (dzvents) code so far:
Code: Select all
return {
on = {
devices = {
"myTest"
},
customEvents = {
"myTestEvent*"
}
},
execute = function(domoticz, object, triggerInfo)
if object.isDevice then
domoticz.log('Device ' .. object.name .. ': state ' ..tostring(object.bState).. '.', domoticz.LOG_FORCE)
if object.bState == true then
local name = 'myTestEvent_' .. tostring(object.idx) .. '_' .. object.lastUpdate.raw
domoticz.emitEvent(name, { idx = object.idx, bState = object.bState, lastUpdate = object.lastUpdate } ).afterSec(10)
end
elseif object.isCustomEvent then
if object.json == nil then
domoticz.log('CustomEvent, ' .. object.customEvent .. ', json is nil.', domoticz.LOG_ERROR)
else
domoticz.log('CustomEvent, ' .. object.customEvent .. ', idx = '.. tostring(object.json.idx) .. ', bState = ' ..tostring( object.json.bState) .. '.', domoticz.LOG_FORCE)
if object.json.idx == nil then
domoticz.log('CustomEvent, ' .. object.customEvent .. ', json.idx is nil.', domoticz.LOG_ERROR)
else
local dev = domoticz.devices(object.json.idx)
if dev == nil then
domoticz.log('CustomEvent, ' .. object.customEvent .. ', device ' .. tostring(object.json.idx) .. ' not found.', domoticz.LOG_ERROR)
else
if dev.bState == object.json.bState and dev.lastUpdate.compare(object.json.lastUpdate).compare == 0 then
domoticz.log('CustomEvent, ' .. object.customEvent .. ', device ' .. dev.name .. ' is still on.', domoticz.LOG_ERROR)
else
domoticz.log('CustomEvent, ' .. object.customEvent .. ', device ' .. dev.name .. ' is no longer on. : ' .. tostring(dev.lastUpdate.rawDateTime) .. ' <> ' .. tostring(object.json.lastUpdate.rawDateTime) .. '.', domoticz.LOG_ERROR)
-- domoticz.utils.dumpTable(object.json.lastUpdate)
-- domoticz.utils.dumpTable(dev.lastUpdate)
end
end
end
end
else
domoticz.log( "unexpected trigger type.", domoticz.LOG_FORCE)
end
end
}
Output from the log (had to filter all other devices' output out):
Code: Select all
2020-06-02 13:41:02.776 (dummy) Light/Switch (myTest)
2020-06-02 13:41:02.760 Status: User: Admin initiated a switch command (552/myTest/Off)
2020-06-02 13:41:03.014 Status: dzVents: !Info: Device myTest: state false.
2020-06-02 13:41:04.066 (dummy) Light/Switch (myTest)
2020-06-02 13:41:04.057 Status: User: Admin initiated a switch command (552/myTest/On)
2020-06-02 13:41:04.275 Status: dzVents: !Info: Device myTest: state true.
2020-06-02 13:41:14.534 Status: dzVents: !Info: CustomEvent, myTestEvent_552_2020-06-02 13:41:02, idx = 552, bState = true.
2020-06-02 13:41:14.553 Error: dzVents: Error: (3.0.5) CustomEvent, myTestEvent_552_2020-06-02 13:41:02, device myTest is no longer on. : 2020-06-02 13:41:04 <> 2020-06-02 13:41:02.
2020-06-02 13:41:14.553 Error: dzVents: Error: (3.0.5) CustomEvent, myTestEvent_552_2020-06-02 13:41:02, device myTest is no longer on. : 2020-06-02 13:41:04 <> 2020-06-02 13:41:02.