Persistent Data problem
Posted: Wednesday 14 June 2017 21:30
I'm sure I'm doing something stupid, but not sure what.
I'm getting this error message from Domoticz logs:
2017-06-14 07:02:00.114 LUA: ...scuit/dev-domoticz/scripts/lua/scripts/SpaPumpSwitch.lua:30: attempt to perform arithmetic on field 'UpdateTimeTotal' (a nil value)
I'm trying to make a persistent variable UpdateTimeTotal which is the time of a switch push, in seconds, so really just an integer.
The error message above is for this line of code (I know the code's logic is wrong, just trying to fix the error message):
DeltaTime = domoticz.data.UpdateTimeTotal + CurrentTimeTotal
Here is the complete code, which is very much a work in progress so please don't laugh
BTW, I'm a HW type, know just enough about SW to be dangerous.
Any help would be most appreciated.
Eventually, this will be used to do something different on a double push of a button versus a single push. Also for debouncing the push button.
Randy
I'm getting this error message from Domoticz logs:
2017-06-14 07:02:00.114 LUA: ...scuit/dev-domoticz/scripts/lua/scripts/SpaPumpSwitch.lua:30: attempt to perform arithmetic on field 'UpdateTimeTotal' (a nil value)
I'm trying to make a persistent variable UpdateTimeTotal which is the time of a switch push, in seconds, so really just an integer.
The error message above is for this line of code (I know the code's logic is wrong, just trying to fix the error message):
DeltaTime = domoticz.data.UpdateTimeTotal + CurrentTimeTotal
Here is the complete code, which is very much a work in progress so please don't laugh
BTW, I'm a HW type, know just enough about SW to be dangerous.
Code: Select all
local Time = require('Time')
local UpdateTime = Time()
--local UpdateTimeTotal -- Update time with hours and mins converted to seconds
local CurrentTimeTotal --Current time with hours and mins converted to seconds
local DeltaTime -- difference between current and update times
return {
active = true,
on = {
['timer'] = 'every minute',
'SpaPumpOnButton',
'SpaPumpCommand',
'SpaHeatOnButton'
},
data = {
UpdateTimeTotal = {initial=1}
},
execute = function(domoticz)
-- UpdateTime=(domoticz.time)
-- print (UpdateTime.hour, UpdateTime.min, UpdateTime.sec)
CurrentTimeTotal = (domoticz.time.hour*3600 + domoticz.time.min*60 + domoticz.time.sec)
print (CurrentTimeTotal)
print (domoticz.data.UpdateTimeTotal)
DeltaTime = domoticz.data.UpdateTimeTotal + CurrentTimeTotal
print (DeltaTime)
if (domoticz.devices['SpaPumpOnButton'].state == 'On') then -- if button pushed
if (domoticz.devices['SpaPumpCommand'].state == 'On') then
domoticz.devices['SpaPumpCommand'].switchOff()
print ('Hey!', 'I am off now!')
else
domoticz.devices['SpaPumpCommand'].switchOn()
print ('Hey!', 'I am on now!')
end
end
end
}Any help would be most appreciated.
Eventually, this will be used to do something different on a double push of a button versus a single push. Also for debouncing the push button.
Randy