Page 1 of 1

device.lastupdate in a device script

Posted: Wednesday 03 February 2021 12:21
by jmleglise
Hi,

I don't understand the use of lastupdate. I thought that on a device script, for the device which trigger the script, it was supposed to return the last modification date before the execution of the script. (not the one which trigger the script).

Look :

Code: Select all

return 
{
    on = 
    {
        devices =  { 'Door3',  },
    },

    execute = function(dz, item)

    print('system:'..dz.time.rawTime)
    print('Domoticz:'..dz.settings.domoticzVersion)
    print('dzvents:'..dz.settings.dzVentsVersion)
    print( ' --------the trigger---------' )   
    print(item.name .. ' seconds ago' ..item.lastUpdate.raw )
    print(item.name .. ' seconds ago' ..dz.devices('Door3').lastUpdate.raw )
    print( ' --------to compare another one ---------' )
    print(dz.devices('Door2').lastUpdate.raw )   
    end
}

2021-02-03 12:11:26.516 (Z-WAVE) General/Alarm (Alarm Type: Access Control 6 (0x06))
2021-02-03 12:11:26.531 (Z-WAVE) Light/Switch (Access Control)
2021-02-03 12:11:26.547 (Z-WAVE) Light/Switch (Door3)
2021-02-03 12:11:26.512 Status: OpenZWave: Alarm received (Access Control: Door/Window Open), NodeID: 7 (0x07)
2021-02-03 12:11:26.838 Status: dzVents: system:12:11:26
2021-02-03 12:11:26.838 Status: dzVents: Domoticz:2020.2
2021-02-03 12:11:26.838 Status: dzVents: dzvents:3.0.2
2021-02-03 12:11:26.838 Status: dzVents: --------the trigger---------
2021-02-03 12:11:26.839 Status: dzVents: Door3 seconds ago2021-02-03 12:11:26
2021-02-03 12:11:26.839 Status: dzVents: Door3 seconds ago2021-02-03 12:11:26
2021-02-03 12:11:26.839 Status: dzVents: --------to compare another one ---------
2021-02-03 12:11:26.841 Status: dzVents: 2021-02-02 23:19:23


My need is simple : I want to play a sound when the door opens, but only if there has been no movement for 5 minutes.
with somehing like : if (item.state == 'Open' and item.lastUpdate.minutesAgo > 2) then


What do you think ?

Re: device.lastupdate in a device script

Posted: Wednesday 03 February 2021 13:33
by waaren
jmleglise wrote: Wednesday 03 February 2021 12:21 What do you think ?
If your version is really V3.5113 (as in your profile) you can hardly expect any useful comment on this question. This version was even before dzVents made it to version 1.0.
Since then many areas of domoticz and dzVents changed and many bugs were fixed among them also some bugs in the area of the lastUpdate processing.

Most recent fix in this area ( github issue 4112) was merged into to V2020.2 build 12002.

Re: device.lastupdate in a device script

Posted: Wednesday 03 February 2021 13:49
by jmleglise
Hi waaren, thank you very much, This drived me crazy ...

I m in 2020.2.11995

So you advice to me to update with the beta channel ? (now : 2020.2.12913)

There is no strange behavior in this one ? :-)

Re: device.lastupdate in a device script

Posted: Wednesday 03 February 2021 13:59
by waaren
jmleglise wrote: Wednesday 03 February 2021 13:49 I m in 2020.2.11995
So you advice to me to update with the beta channel ? (now : 2020.2.12913)
My only advise it to update your profile :) .
if you want to move to the beta channel is up to you.
There is no strange behavior in this one ? :-)
If you mean to ask if this Beta is without bugs?
Yes. It's 100% error free and even world peace is now implemented