getting a nil error. probably a simple fix  [Solved]

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

Moderator: leecollings

Post Reply
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

getting a nil error. probably a simple fix

Post by Gravityz »

well, i am getting rusty with dzvents


i am trying to time the time between a device gets updated but i am getting a nil error
i declared a global variable but somehow something is still wrong

also tried WatermeterDeltaTime = domoticz.time.compare('Watermeter').lastUpdate.ms but that did not help either

in the global_data is this

Code: Select all

WatermeterDeltaTime = { initial = 9999 },

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'Watermeter'
        }
    },
    execute = function(domoticz, Watermeter)
        WatermeterDeltaTime = domoticz.time.compare(Watermeter.lastUpdate.ms)
        if WatermeterDeltaTime <= 9000 then
         domoticz.devices('fastpulse').updateWaterflow(WatermeterDeltaTime)   
            
            end
       --domoticz.devices('fastpulse').updateWaterflow(1)
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: getting a nil error. probably a simple fix

Post by waaren »

Gravityz wrote: Friday 22 January 2021 9:27 well, i am getting rusty with dzvents
You compare a time object (domoticz.time) with a number(Watermeter.lastUpdate.ms)

can you try again after changing

Code: Select all

WatermeterDeltaTime = domoticz.time.compare(Watermeter.lastUpdate.ms)
to

Code: Select all

WatermeterDeltaTime = domoticz.time.compare(Watermeter.lastUpdate).ms

That will compare two time objects and returns the ms attribute
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Gravityz
Posts: 652
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: getting a nil error. probably a simple fix  [Solved]

Post by Gravityz »

thanks,

working now.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest