Strange behaviour persistent data in dzVents in domoticz 3.8153

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

Moderator: leecollings

Post Reply
Bertvdw
Posts: 19
Joined: Sunday 08 October 2017 23:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Strange behaviour persistent data in dzVents in domoticz 3.8153

Post by Bertvdw »

When converting my old lua scripts with dzVentz 1.1 i discoverd some strange/incorrect behaviour with the persistent data.
I occurs when i try to save the previous state of a domotics device with an initial value of nil or {}.

Every time the script runs the persistent data is reset to nil instead of only the first time.

I created two testscript:

script 1:

This script run as espected, the value test increases with one every run

-- Start script

Code: Select all

return {
  on = { timer = {'every minute'} 
       },
  data = { test = {initial = 1 }
         },
  execute = function(domoticz, d)
      domoticz.data.test = domoticz.data.test + 1
      domoticz.log(  'TestData1 -- aantal = ' .. domoticz.data.test , LOG_INFO )
   end -- function
}
script 2:

Every run i get the following result.
As you can see, the script starts with the initial data every run for all variables the data segment

2017-10-15 19:41:00.363 dzVents: Info: device nil
2017-10-15 19:41:00.380 dzVents: Info: device RaamSlaapkamer
2017-10-15 19:41:00.380 dzVents: Info: test: 123
2017-10-15 19:41:00.380 dzVents: Info: test: 1

Code: Select all

return {
  on = { timer = {'every minute'} 
       },
  data = { test = {initial = 123 }
         , dev = {initial = nil}
         },
  execute = function(domoticz, d)
    
    if ( not domoticz.data.dev ) then
      domoticz.log(  'device nil', LOG_INFO )
      domoticz.data.dev = domoticz.devices("RaamSlaapkamer")
      domoticz.log(  'device ' .. domoticz.data.dev.name , LOG_INFO )
    else 
      domoticz.log(  'device set', LOG_INFO )
    end
    domoticz.log(  'test: ' .. domoticz.data.test, LOG_INFO ) 
    domoticz.data.test = 1        
    domoticz.log(  'test: ' .. domoticz.data.test, LOG_INFO )
   end -- function
}

What am i doing wrong?

Bert
Last edited by dannybloe on Monday 16 October 2017 11:01, edited 1 time in total.
Reason: Use code formatting
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Strange behaviour persistent data in dzVents in domoticz 3.8153

Post by dannybloe »

Well, the problem is that you are assigning a device object to your variable and that's something you'd better not do as the object has functions and they cannot be serialized to the persistent store. So better you just put in the variable what you actually need instead of the entire device object.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Bertvdw
Posts: 19
Joined: Sunday 08 October 2017 23:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Strange behaviour persistent data in dzVents in domoticz 3.8153

Post by Bertvdw »

Thanks for your reaction Danny.
I will try your suggestion.

The reason why i stored the complete device object in the the data variable is because of the example in the dzVents documentation ( in the persistent data chapter).

You can define as many variables as you like and put whatever value in there that you like. It doesn't have to be just a number, you can even put the entire device state in it:
return {
active = true,
on = {
devices = { 'MySwitch' }
},
data = {
previousState = {initial=nil}
},
execute = function(domoticz, switchDevice)
-- set the previousState:
domoticz.data.previousState = switchDevice

-- read something from the previousState:
if (domoticz.data.previousState.temperature > .... ) then
end
end
}


Bert
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Strange behaviour persistent data in dzVents in domoticz 3.8153

Post by dannybloe »

Yep.. indeed.. that wasn't good advice, now was it? ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Bertvdw
Posts: 19
Joined: Sunday 08 October 2017 23:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Strange behaviour persistent data in dzVents in domoticz 3.8153

Post by Bertvdw »

I'll try tonight.
I'll let you know if it's working.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest