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
}
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