When is 'lastupdate' triggered?

Moderator: leecollings

Post Reply
jake
Posts: 751
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

When is 'lastupdate' triggered?

Post by jake »

I have 2 questions about the 'lastupdate' feature/command in LUA:
1: does it always run in an 'device' or 'time' LUA file?

2: How often does the 'lastupdate' check how much time is between 'Now' and the last update of the device?
I want to execute something 3 seconds after the Kodi media player switches from 'On' to 'Audio' or 'Video'. I tried to use this piece of code for it in a device_lua script, but it doesn't run when I start to play something in Kodi. Strange enough it fires sometimes when Kodi goes to 'Pause' or 'On'

Code: Select all

if (timedifference(otherdevices_lastupdate['Kodi Media Center']) > 3 and timedifference(otherdevices_lastupdate['Kodi Media Center']) < 15) then
	print('Test kodi last update')
End
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: When is 'lastupdate' triggered?

Post by jvdz »

Looks like you are little confused when reading the questions. :)
Whenever an event is triggered, being a time, device or variable change, the appropriate tables are build like the otherdevices_lastupdate table.
So that information in there is the information at event trigger time.

Does that make sense?

Jos
jake
Posts: 751
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: When is 'lastupdate' triggered?

Post by jake »

jvdz wrote:Looks like you are little confused when reading the questions. :)
Whenever an event is triggered, being a time, device or variable change, the appropriate tables are build like the otherdevices_lastupdate table.
So that information in there is the information at event trigger time.

Does that make sense?

Jos
Sorry for the late reply. I have to admit it doesn't make sense (yet). Am I correct to say that an event is needed to make the LUA script check the 'age' of the lastupdate?

How would I create a 3 second delay? Reason for needing is, that when Kodi starts playing, I turn on the Onkyo receiver and depending on 'audio' or 'video', I change the listening mode. However, during 'boot' of the Onkyo, it won't listen to the next command, I therefore want to wait 3 seconds before changing the listening mode.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: When is 'lastupdate' triggered?

Post by Egregius »

Same thing with a Denon, especially now that I also cut his power.
But solved it:

Code: Select all

function denon(){
    if($this->a=="On"){
        if($this->s['denonpower']=='Off') {$this->sw($this->i['denonpower'],'On','denonpower');sleep(8);}
        for($x=0;$x<=10;$x++){
            sleep(1);
            $denon=json_decode(json_encode(simplexml_load_string(file_get_contents($this->denon.'/goform/formMainZone_MainZoneXml.xml?_='.time(),false, $this->ctx))), TRUE);
            if($denon['ZonePower']['value']!='ON') {
                file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON&cmd1=aspMainZone_WebUpdateStatus%2F',false,$this->ctx);
                sleep(1);
                file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON&cmd1=aspMainZone_WebUpdateStatus%2F&ZoneName=ZONE2',false,$this->ctx);
                sleep(1);
                file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_InputFunction/TUNER',false,$this->ctx);
            } else break;
        }
    }else{
        file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF&cmd1=aspMainZone_WebUpdateStatus%2F&ZoneName=ZONE2',false,$this->ctx);
        sleep(1);
        file_get_contents($this->denon.'/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF&cmd1=aspMainZone_WebUpdateStatus%2F',false,$this->ctx);
        sleep(5);
        $this->sw($this->i['denonpower'],'Off','denonpower');
    }
}
 
So if I want to switch the Denon on, it first checks if the powerswitch is on, if not switch it on and wait 8 seconds.
Then try in a loop to get the current status, as soon as it responds break the loop.
Then continue and power up zone1, power up zone2 and select tuner as input.
I also have other devices that select other inputs or first ask the current volume to add or deduct 3 steps to it.
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: When is 'lastupdate' triggered?

Post by niceandeasy »

Domoticz is event-driven. If nothing changes, no LUA scripts will ever be called, except for time scripts, every minute. When a change triggers a script, the script should finish as fast as possible and return the result back to Domotics via the commandArray. Domoticz will execute the actions/commands as fast as possible. During the usually very short time a script is running, Domoticz is unresponsive.
The proper way to use short delays in your Domotica system is to use Domoticz to trigger an external script in a way that Domoticz can carry on doing what it does best, while the external script runs parallel. The external script can have delays and might even trigger events in Domoticz while it runs, by using json calls to Domoticz.
Native Domoticz seems to only have provisions for delays in the order of minutes, for example by using "On FOR x" in the commandArray. X is the number of minutes.

Disclaimer: I did not research to compose this answer. Maybe there IS a good way to introduce short delays that I don't know about.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest