Code: Select all
2021-04-13 03:38:00.239 Error: dzVents: Error: (3.1.7) graaddagen: An error occurred when calling event handler graaddagen
2021-04-13 03:38:00.239 Error: dzVents: Error: (3.1.7) graaddagen: ...omoticz\scripts\dzVents\generated_scripts/graaddagen.lua:57: attempt to index a nil value (local '_')
Maybe that has something to do with it?
waaren wrote: Wednesday 11 November 2020 16:26 Below example uses lodash (standard packaged with dzVents) to do the iteration for you
Code: Select all
local scriptVar = 'averageTemp' return { on = { timer = { 'at 23:45', }, httpResponses = { scriptVar, }, }, logging = { level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK marker = scriptVar, }, execute = function(dz, item) local _ = dz.utils._ -- lodash if item.isTimer then dz.log('Calling dz temp average..', dz.LOG_DEBUG) dz.openURL( { -- 131 outdoor temp sensor url = dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=temp&idx=131&range=month', callback = scriptVar, }) return end if item.isHTTPResponse and item.isJSON then local heatingStart = 18 -- standard correction factor local rt = item.json.result dz.log('Finding today in the result table using lodash find', dz.LOG_DEBUG) local today = _.find(rt, function (rt) return rt.d == dz.time.rawDate end ) if today and ( heatingStart - today.ta ) > 0 then -- idx 267 Graaddagen dummy sensor dz.log('Average temp for today is ' .. dz.utils.round(today.ta, 2 ) .. ' °C ', dz.LOG_DEBUG) dz.devices(267).updateTemperature( dz.utils.round( today.ta, 2 ) ) end else dz.log('Return table is not OK', dz.LOG_ERROR) dz.log(item, dz.LOG_DEBUG) end end }