build 13151 seems to break the script 'graaddagen'  [Solved]

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

Moderator: leecollings

Post Reply
plugge

build 13151 seems to break the script 'graaddagen'

Post by plugge »

Since build 13151 the script graaddagen (below) breaks:

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 '_')
13151 removed duplicate templates https://github.com/domoticz/domoticz/co ... 02992a886a
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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: build 13151 seems to break the script 'graaddagen'

Post by waaren »

plugge wrote: Tuesday 13 April 2021 11:09 Since build 13151 the script graaddagen (below) breaks:

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 '_')
https://github.com/domoticz/domoticz/co ... 02992a886a
Maybe that has something to do with it?
thx for reporting!

Is indeed caused by a change in this commit. Will be fixed in a next build but you can already workaround it by changing
line

Code: Select all

        local _ = dz.utils._           -- lodash
to

Code: Select all

       local _ = require('lodash')          -- lodash
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest