help with dzventsscript
Posted: Wednesday 21 November 2018 17:09
Hi, i tried to read temperaturesensor based on weatherunderground. Got it almost working.
I get an error on variable prevwaarde, it seems to have no value?
- I added a initial value of 100 in the data section and
- i checked if this global variable is empty and set it to 100
Both dont seemed to work...
I get an error on variable prevwaarde, it seems to have no value?
- I added a initial value of 100 in the data section and
- i checked if this global variable is empty and set it to 100
Both dont seemed to work...
Code: Select all
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor device = Zuiderparklaan
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor id to update = 826
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor grenswaarde = 2
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor huidige waarde= 2.4000000953674
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): An error occured when calling event handler test2
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): .../pi/domoticz/scripts/dzVents/generated_scripts/test2.lua:33: attempt to index global 'domoticz' (a nil value)
Code: Select all
-- soon more sensor temp device will be added to this script
local TMP_DEVICES = {
['Zuiderparklaan'] = 'Zuiderparklaan', -- Adjust to your needs. Between every line you need to add a ",".
}
local USAGE_tmpnorm = {
['Zuiderparklaan'] = 2, -- Adjust to your needs. Between every line you need to add a ",".
}
return {
on = { devices = TMP_DEVICES },
logging = { level = domoticz.LOG_DEBUG , -- Uncomment to override the dzVents global logging setting
marker = actOnIdleDevices
},
data = {
prevhistwaarde = { history = true, maxItems = 10, initial=100 }
},
execute = function(dz, device)
local name = device.name
local norm = USAGE_tmpnorm[TMP_DEVICES[name]]
local huidwaarde = device.temperature
--function round2(num, numDecimalPlaces)
--return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
-- end
if dz.data.prevhistwaarde[name] == nil then
dz.log("00 Sensor info = Geen vorige waarde opgehaald")
local prevwaarde = 100
else
local prevwaarde = dz.data.prevhistwaarde[name]
end
dz.log("00 Sensor device = " .. name)
dz.log("00 Sensor grenswaarde = " .. norm)
dz.log("00 Sensor huidige waarde= " .. tostring(huidwaarde))
dz.log("00 Sensor vorige waarde = " .. tostring(prevwaarde))
dz.log("---------------------------------------")
if huidwaarde == nil then
dz.log("01 Sensor info = Geen waarde opgehaald")
else
if (huidwaarde - prevwaarde == 0 ) then
dz.log("02 Sensor info = Oude en nieuwe sensorwaarden zijn gelijk")
else
dz.log("03 Sensor info = Nieuwe sensorwaarde...")
domoticz.devices('temperatuur').updateTemperature(huidwaarde)
domoticz.data.prevhistwaarde.add(huidwaarde)
end
end
end
}