Page 1 of 1

dzVents error [nil value]

Posted: Sunday 09 July 2023 10:47
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.

Re: dzVents error [nil value]

Posted: Sunday 09 July 2023 11:53
by habahabahaba
Look at
local vandaagKwhzon
Its device, not value

Re: dzVents error [nil value]

Posted: Monday 10 July 2023 9:36
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?

Re: dzVents error [nil value]

Posted: Monday 10 July 2023 10:25
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

Re: dzVents error [nil value]

Posted: Monday 10 July 2023 11:13
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)

Re: dzVents error [nil value]  [Solved]

Posted: Monday 10 July 2023 19:03
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.

Re: dzVents error [nil value]

Posted: Monday 10 July 2023 21:07
by habahabahaba
Exactly as @waltervl said
Watch what is the type of device and then to the wiki

Re: dzVents error [nil value]

Posted: Monday 10 July 2023 21:49
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.

Re: dzVents error [nil value]

Posted: Tuesday 11 July 2023 8:49
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