dzVents error [nil value]  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
lsp242
Posts: 57
Joined: Sunday 04 February 2018 8:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 12923
Location: Netherlands
Contact:

dzVents error [nil value]

Post by lsp242 »

I try to calculate daily energy costs with input found on huizebruin.nl (error message on the code) and krijnemerins.nl where the solar panels are not in the script.

Via a Node Red I get my actual production on dummy device "day production". I have linked this in the script for the calculation.

I don't know exactly how I want to do it yet, but I want to finish this dzVents calculation for myself now. In the end, it may be better to use p1 to calculate yield and life for each phase.

But with this code below I get an error.

Code: Select all

return {
      on = { 
        timer = {
           'every 15 minutes'            
        },
    }, 
    execute = function(domoticz, device, timer)

        local vandaagKwh      = domoticz.devices('Power').counterToday 
        local vandaagM3Gas    = domoticz.devices('Gas').counterToday 
        local vandaagKwhzon    = domoticz.devices('Day Production')
               
        local StroomKosten  = domoticz.devices('Kosten Stroom')
        local GasKosten     = domoticz.devices('Kosten Gas')
        local Kosten = domoticz.devices('Kosten Stroom + Gas')
        local Opbrengsten = domoticz.devices('Levering Stroom')
        
        -- Eenheidsprijs in Euro's / Kwh - M3
        local kwhPrijs = 0.21
        local kwhPrijszon = 0.18
        local gasM3Prijs = 0.70
         if (domoticz.time == 'Between 23:00 and 07:00') or (domoticz.day == 'Saturday') or (domoticz.day == 'Sunday') then
            kwhPrijs = 0.19 -- Daltarief
        else
            kwhPrijs = 0.21 -- Normaal tarief
        end 
       
        -- Vaste kosten in Euro's per dag (zoals vastrecht) 
        local kwhPrijsVast = 0.05
        local gasM3PrijsVast = 0.06
        
        -- Kosten berekenen
        local kwhKosten = tonumber(domoticz.utils.round( (kwhPrijs * vandaagKwh) + kwhPrijsVast,2))   
        local GasM3Kosten = tonumber(domoticz.utils.round( (gasM3Prijs * vandaagM3Gas) + gasM3PrijsVast,2))
        local Kostentotaal = kwhKosten + GasM3Kosten
        local Teruglevering = tonumber(domoticz.utils.round( (kwhPrijszon * vandaagKwhzon),2))
      
        -- Kosten updaten
          StroomKosten.updateCustomSensor(kwhKosten)
          GasKosten.updateCustomSensor(GasM3Kosten)
          Kosten.updateCustomSensor(Kostentotaal)
          Opbrengsten.updateCustomSensor(Teruglevering)
    end
} 
De errorcode:

Code: Select all

2023-07-09 10:09:00.224 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler Dagkosten dummy sensor
2023-07-09 10:09:00.224 Error: dzVents: Error: (3.1.8) ...pts/dzVents/generated_scripts/Dagkosten dummy sensor.lua:36: attempt to perform arithmetic on a nil value (local 'vandaagKwhzon')
I'm probably doing something stupid.. :mrgreen:

I also wonder how the correct calculation should be for the real money my solar panels deliver, when using P1 and solar panel count.
Gadget freak - Domoticz beginner - ios and android user
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents error [nil value]

Post by habahabahaba »

Look at
local vandaagKwhzon
Its device, not value
User avatar
lsp242
Posts: 57
Joined: Sunday 04 February 2018 8:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 12923
Location: Netherlands
Contact:

Re: dzVents error [nil value]

Post by lsp242 »

habahabahaba wrote: Sunday 09 July 2023 11:53 Look at
local vandaagKwhzon
Its device, not value
Why does it read the values from f.e. vandaagKwh ? that is a device who gets the P1 information and with that can calculation the cost..

vandaagKwhzon is also a device "Day Production" filled from Node Red scraping from the solar panels. How do I get from that device the value to calculate?
Gadget freak - Domoticz beginner - ios and android user
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents error [nil value]

Post by habahabahaba »

In local vandaagKwh = domoticz.devices('Power').counterToday you sre getting value "counterToday"

In local vandaagKwhzon = domoticz.devices('Day Production') you declare the device but not the value of it
User avatar
lsp242
Posts: 57
Joined: Sunday 04 February 2018 8:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 12923
Location: Netherlands
Contact:

Re: dzVents error [nil value]

Post by lsp242 »

habahabahaba wrote: Monday 10 July 2023 10:25 In local vandaagKwh = domoticz.devices('Power').counterToday you sre getting value "counterToday"

In local vandaagKwhzon = domoticz.devices('Day Production') you declare the device but not the value of it
@habahabahaba I understand that part, but how to know what should be there, because "counterToday" also fails. (maybe stupid questions, but i'm lost)
Gadget freak - Domoticz beginner - ios and android user
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: dzVents error [nil value]  [Solved]

Post by waltervl »

The declaration should mach the type of device. So what kind of devices are the devices called 'Power' and 'Day Production' ? Then look into the Dzvents wiki documentation to check the correct declaration.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: dzVents error [nil value]

Post by habahabahaba »

Exactly as @waltervl said
Watch what is the type of device and then to the wiki
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: dzVents error [nil value]

Post by willemd »

It could also be the name 'Day Production' . If that does not exactly match the name of the device you will get the same errors. Check the spelling or use the idx number of the device.
User avatar
lsp242
Posts: 57
Joined: Sunday 04 February 2018 8:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 12923
Location: Netherlands
Contact:

Re: dzVents error [nil value]

Post by lsp242 »

Thank you very much to putting me to the right direction! it should be:

Code: Select all

local vandaagKwhzon = domoticz.devices('Day Production').SensorValue
Gadget freak - Domoticz beginner - ios and android user
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest