Add two kWh meters

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

Moderator: leecollings

Post Reply
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Add two kWh meters

Post by MikeyMan »

Hi all,
Yesterday i installed my second inverter with a couple of panels.
Now i'm trying to add the numbers up to a total. Feel i'm getting close, but not working yet.
return
{
on =
{
timer = {
'every minute'
}
},

logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Totaal Zonnepanelen',
},

execute = function(domoticz, device, item)

-- targetDevice = domoticz.devices(647) -- define as virtual custom sensor

local SolarEdge = domoticz.devices(9).counterToday
local Goodwe = domoticz.devices(632).counterToday
local Total = SolarEdge + Goodwe

domoticz.log('Totaalopbrengst Zonnepanelen counterToday: ' .. Total)

-- targetDevice.updateCustomSensor(Total)
domoticz.devices(647).updateCustomSensor(Total)
end
}
Log says:
2023-03-05 11:59:00.186 Status: dzVents: Info: Totaal Zonnepanelen: ------ Start internal script: Script #2:, trigger: "every minute"
2023-03-05 11:59:00.187 Status: dzVents: Debug: Totaal Zonnepanelen: Processing device-adapter for kWh Meter Inverter 1: kWh device adapter
2023-03-05 11:59:00.188 Status: dzVents: Debug: Totaal Zonnepanelen: Processing device-adapter for Goodwe zonnepanelen - Inverter output power (SN: 51000SSX22BW0018): kWh device adapter
2023-03-05 11:59:00.189 Status: dzVents: Info: Totaal Zonnepanelen: Totaalopbrengst Zonnepanelen counterToday: 3.4
2023-03-05 11:59:00.190 Status: dzVents: Debug: Totaal Zonnepanelen: Processing device-adapter for Totaal opbrengst: kWh device adapter
2023-03-05 11:59:00.190 Status: dzVents: Info: Totaal Zonnepanelen: ------ Finished Script #2
2023-03-05 11:59:00.190 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateCustomSensor is not available for device "Totaal opbrengst" (deviceType=General, deviceSubType=kWh). If you believe this is not correct, please report.
also tried a generic counter, but same error:
2023-03-05 12:02:00.285 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateCustomSensor is not available for device "Totaal opbrengst" (deviceType=General, deviceSubType=kWh). If you believe this is not correct, please report.
2023-03-05 12:02:00.286 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateCustomSensor is not available for device "test totaal" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
Can you not write values to a kWh custom device :?
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Add two kWh meters

Post by roblom »

I'm no expert but maybe it helps.. I think in the first attempt you try to update the "Totaal" device. In the second attempt you use the "test total" device but this is not a custom device I think
Why do you want too use a custom sensor? Maybe try .updateElectricity?

For more info see
https://www.domoticz.com/wiki/DzVents:_ ... counter.29

Last edited by roblom on Sunday 05 March 2023 15:46, edited 2 times in total.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Add two kWh meters

Post by MikeyMan »

roblom wrote: Sunday 05 March 2023 15:46 Why do you use a custom sensor? Maybe try .updateElectricity?

For more info see
https://www.domoticz.com/wiki/DzVents:_ ... counter.29
Is there another way to add a dummy device?

I'll give that a try thanks!
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Add two kWh meters

Post by MikeyMan »

No luck yet:

2023-03-05 16:40:00.195 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateElectricity is not available for device "test totaal" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
2023-03-05 16:41:00.198 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateElectricity is not available for device "test totaal" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Add two kWh meters

Post by willemd »

Apparently it is not a generic custom sensor but a kwh device? So then you need to use updateElectricity()
https://www.domoticz.com/wiki/DzVents:_ ... counter.29
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Add two kWh meters

Post by willemd »

MikeyMan wrote: Sunday 05 March 2023 16:41 No luck yet:

2023-03-05 16:40:00.195 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateElectricity is not available for device "test totaal" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
2023-03-05 16:41:00.198 Error: dzVents: Error: (3.1.8) Totaal Zonnepanelen: Method updateElectricity is not available for device "test totaal" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
and for the rfxmeter counter you need to use updateCounter()

Check the wiki, each type of device has its own update method.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Add two kWh meters

Post by MikeyMan »

Thanks for the tips, was a bit lost with the device types.
Change to Energy(Usage) type and this script:

Code: Select all

return
{
    on =
    {
        timer = {
			'every minute'       
                  }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Totaal Zonnepanelen',
    },

    execute = function(domoticz, device, item)

        local SolarEdge = domoticz.devices(9).counterToday
        local Goodwe = domoticz.devices(632).counterToday
        local Total = SolarEdge + Goodwe

        domoticz.log('Totaalopbrengst Zonnepanelen counterToday: ' .. Total)

        domoticz.devices(648).updateEnergy(Total)
    end
}
And it seems to be working :D
Although now it shows current wattage instead of totals.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Add two kWh meters

Post by MikeyMan »

Changed the type around again. Seems to be working for current value. Not so much for the daily totals yet ;)

Code: Select all

return
{
    on =
    {
--        timer = {
--			'every minute'       
--                }
        devices =   {
            9,
            632
                    }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Totaal Zonnepanelen',
    },

    execute = function(domoticz, device, item)

        local SolarEdgeToday = domoticz.devices(9).counterToday
        local SolarEdge = domoticz.devices(9).actualWatt
        local GoodweToday = domoticz.devices(632).counterToday
        local Goodwe = domoticz.devices(632).actualWatt
        local Total = SolarEdge + Goodwe
        local TotalToday = SolarEdgeToday + GoodweToday

        domoticz.log('Totaalopbrengst Zonnepanelen actualWatt: ' .. Total)
        domoticz.log('Totaalopbrengst Zonnepanelen counterToday ' .. TotalToday)

--        domoticz.devices(648).updateEnergy(Total)
        domoticz.devices(649).updateElectricity(Total,TotalToday)
    end
}
Strangely enough the log does show changing values:

Code: Select all

2023-03-06 10:36:45.883 Status: dzVents: Info: Handling events for: "Solaredge - kWh Meter Inverter 1", value: "1009.000;26433400.000"
2023-03-06 10:36:45.883 Status: dzVents: Info: Totaal Zonnepanelen: ------ Start internal script: Zonnepanelen: Device: "Solaredge - kWh Meter Inverter 1 (Zonnepanelen)", Index: 9
2023-03-06 10:36:45.884 Status: dzVents: Debug: Totaal Zonnepanelen: Processing device-adapter for Goodwe - Inverter output power: kWh device adapter
2023-03-06 10:36:45.885 Status: dzVents: Info: Totaal Zonnepanelen: Totaalopbrengst Zonnepanelen actualWatt: 1225.0
2023-03-06 10:36:45.885 Status: dzVents: Info: Totaal Zonnepanelen: Totaalopbrengst Zonnepanelen counterToday 2.2
2023-03-06 10:36:45.886 Status: dzVents: Debug: Totaal Zonnepanelen: Processing device-adapter for Totaal opbrengst: kWh device adapter
2023-03-06 10:36:45.886 Status: dzVents: Info: Totaal Zonnepanelen: ------ Finished Zonnepanelen
2023-03-06 10:36:45.887 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
Am i still using the device wrong?

Ah, WhToday makes more sense of the data ;)
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Add two kWh meters

Post by willemd »

For a KWH device you have a choice between "computed" and "from device" when you click on the edit button of the device.
If it is "computed" then the daily value is calculated from the actual values, which is less accurate.
If you have counter values that you want to put on the device then it is best to choose "from device".
roelvdh
Posts: 37
Joined: Saturday 18 January 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: NL
Contact:

Re: Add two kWh meters

Post by roelvdh »

I am trying to use this. I have added 2 kWh values of 2 devices (solar batteries) into variable Totaal and want to put this total into a virtual sensor, idx 315, type=General, subtype=kWh. I tried your suggestion using:

Code: Select all

domoticz.devices(315).computed = Totaal
It runs fine but nothing happens to my virtual device. I just started using dzVents and do not yet understand some of the peculiarities. For instance: How can I find the usable arguments of the fuction domoticz.devices()? You would expect the Domoticz editor to provide such information. sqlite3 domoticz.db didn't help either. Normal road blocks for a starter, I suppose.
Last edited by roelvdh on Sunday 13 October 2024 21:52, edited 1 time in total.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Add two kWh meters

Post by FlyingDomotic »

Is Totaal Zonnepanelen a kWh counter?
roelvdh
Posts: 37
Joined: Saturday 18 January 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: NL
Contact:

Re: Add two kWh meters

Post by roelvdh »

No, but my 2 devices are and I am otherwise using the same code. Only, the virtual device containing the added kWh's is not hit.

Edit: The answer is in the docs, as always. I just had not found where to search for this answer. Solved.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests