lastUpdate not the last!

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

lastUpdate not the last!

Post by hestia »

I've discovered there https://github.com/domoticz/domoticz/issues/4466
that
When the script is triggered by the device update you already know when it is updated (it is updated now)
The lastupdate value is updated after the script is triggered.
[...]
but my comment is true for scripts triggered by the device update. If you use a time based script or a script triggered by a different device and probe for the lastUpdate time it should report the real lastUpdate time

This is how it should work by design
But I think it doesn't work like this...
2 scripts to test it

Code: Select all

-- the trigger script

LOGGING = domoticz.LOG_DEBUG
LOG_LEVEL = domoticz.LOG_DEBUG

local dev0 = 214
local dev1 = 271
local dev2 = 460

return {
    logging =   {   level   =   LOGGING,
	            },
	on = {

		devices = {dev0}

		},

	execute = function(dz, triggerObject)
	_G.logMarker =  dz.moduleLabel

    dz.devices(dev1).toggleSwitch()
    dz.devices(dev2).toggleSwitch()

end
}

Code: Select all

-- the triggered script

LOGGING = domoticz.LOG_DEBUG
LOG_LEVEL = domoticz.LOG_DEBUG

local dev1 = 271
local dev2 = 460

return {
    logging =   {   level   =   LOGGING,
	            },
	on = {

		devices = {dev1}

		},

	execute = function(dz, triggerObject)
	_G.logMarker =  dz.moduleLabel

    dz.log(dz.devices(dev1).id .. ' ' .. dz.devices(dev1).lastUpdate.raw)
    dz.log(dz.devices(dev2).id .. ' ' .. dz.devices(dev2).lastUpdate.raw)

end
}
the log
Spoiler: show
2022-06-26 19:40:35.198 Status: dzVents: Info: ------ Start internal script: z_trigger: Device: "test 214 (Dummy)", Index: 214
2022-06-26 19:40:35.204 Status: dzVents: Debug: z_trigger: Processing device-adapter for test 271: Switch device adapter
2022-06-26 19:40:35.204 Status: dzVents: Debug: z_trigger: Constructed timed-command: On
2022-06-26 19:40:35.206 Status: dzVents: Debug: z_trigger: Processing device-adapter for test 460: Switch device adapter
2022-06-26 19:40:35.207 Status: dzVents: Debug: z_trigger: Constructed timed-command: On
2022-06-26 19:40:35.207 Status: dzVents: Info: z_trigger: ------ Finished z_trigger
2022-06-26 19:40:35.648 Status: dzVents: Info: ------ Start internal script: z_triggered: Device: "test 271 (Dummy)", Index: 271
2022-06-26 19:40:35.648 Status: dzVents: Info: z_triggered: 271 2022-03-28 21:26:25
2022-06-26 19:40:35.650 Status: dzVents: Debug: z_triggered: Processing device-adapter for test 460: Switch device adapter
2022-06-26 19:40:35.650 Status: dzVents: Info: z_triggered: 460 2022-03-17 21:40:16
2022-06-26 19:40:35.650 Status: dzVents: Info: z_triggered: ------ Finished z_triggered
2022-06-26 19:41:59.487 Status: dzVents: Info: ------ Start internal script: z_trigger: Device: "test 214 (Dummy)", Index: 214
2022-06-26 19:41:59.489 Status: dzVents: Debug: z_trigger: Processing device-adapter for test 271: Switch device adapter
2022-06-26 19:41:59.489 Status: dzVents: Debug: z_trigger: Constructed timed-command: Off
2022-06-26 19:41:59.491 Status: dzVents: Debug: z_trigger: Processing device-adapter for test 460: Switch device adapter
2022-06-26 19:41:59.491 Status: dzVents: Debug: z_trigger: Constructed timed-command: Off
2022-06-26 19:41:59.492 Status: dzVents: Info: z_trigger: ------ Finished z_trigger
2022-06-26 19:41:59.738 Status: dzVents: Info: ------ Start internal script: z_triggered: Device: "test 271 (Dummy)", Index: 271
2022-06-26 19:41:59.738 Status: dzVents: Info: z_triggered: 271 2022-06-26 19:40:35
2022-06-26 19:41:59.740 Status: dzVents: Debug: z_triggered: Processing device-adapter for test 460: Switch device adapter
2022-06-26 19:41:59.740 Status: dzVents: Info: z_triggered: 460 2022-06-26 19:40:35
2022-06-26 19:41:59.740 Status: dzVents: Info: z_triggered: ------ Finished z_triggered
The script is triggered by dev1 = 271, so it's lastUpdate is the previous one => OK

Code: Select all

z_triggered: 271 2022-06-26 19:40:35
But it's the same for the other device dev2 = 460

Code: Select all

z_triggered: 460 2022-06-26 19:40:35
even though it was updated after

Code: Select all

2022-06-26 19:41:59.491 Status: dzVents: Debug: z_trigger: Processing device-adapter for test 460: Switch device adapter
2022-06-26 19:41:59.491 Status: dzVents: Debug: z_trigger: Constructed timed-command: Off
and that it was not the trigger!
You would say that, we could know that it was updated with the one triggered, but we could have different conditions for the update and so the result is that we don't know if it was updated or not :-(
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest