combine power to single sensor  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

combine power to single sensor

Post by jacobsentertainment »

Hi all,

I have this script and it works so far, no errors in the log.

I want to combine the power of three sensors and display that in a dummy sensor (kWh) So far I can see in the log the combined/totalled power.
The sensor 'Totaal Kwh Growatt' is updating but there is no value displayed. If I look in the device tab at this sensor then I do see under data the values changing.

What am I doing wrong here?

Code: Select all

return
{
    on =
    {
        devices =
        {
            499, 503, 507
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'totaal vermogen',
    },

    execute = function(dz)
        local L1 = dz.devices(499).actualWatt
        local L2 = dz.devices(503).actualWatt
        local L3 = dz.devices(507).actualWatt
        local combinedUsage = dz.devices('Totaal Kwh Growatt')
        
        local totpower = ( L1 + L2 + L3 )
    
        combinedUsage.update(totpower, WhActual)
        
        dz.log('# totaal vermogen = '..totpower..'')

    end
}
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: combine power to single sensor  [Solved]

Post by waltervl »

Code: Select all

combinedUsage.update(totpower, WhActual)
What is WhActual? I think you have mixed up the values.
I think you have to send totpower = 0 but not sure this works for this device.
WhActual = L1+L2+L3
And then use other way around

Code: Select all

combinedUsage.update(WhActual, totpower)
POWER = current power = WhActual
ENERGY = Integer, total cumulative energy in Watt-hours (Wh) = totpower = 0
Also WhActual is a DzVents function name so perhaps better to call it WhActualCombined

Alternatively you can make a dummy Electrical Usage devive
https://www.domoticz.com/wiki/Dummy_for ... lectricity
https://www.domoticz.com/wiki/DzVents:_ ... tric_usage

That needs only 1 parameter
.updateEnergy(energy)
eg

Code: Select all

WhActualCombined = L1+L2+L3
combinedUsage.updateEnergy(WhActualCombined)
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
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: combine power to single sensor

Post by jacobsentertainment »

Created a new dummy "Electrical Usage device " and that did the trick. The old one was an "General kWh"
I was probably to much focused on the script and didn't paid attention to the sensor it self.
Thanks Walter, you seem to be al over the forum :-)

And the final script

Code: Select all

return
{
    on =
    {
        devices =
        {
            499, 503, 507
        }
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = 'totaal vermogen',
    },

    execute = function(dz)
        local L1 = dz.devices(499).actualWatt
        local L2 = dz.devices(503).actualWatt
        local L3 = dz.devices(507).actualWatt
        local combinedUsage = dz.devices(511)
        
        local totpower = ( L1 + L2 + L3 )
    
        combinedUsage.update(0,totpower)
        
        dz.log('# totaal vermogen = '..totpower..'')

    end
}
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

i gone try to copy this :D
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

in my case i have a error.

i create this dummy for the picture.

Error: EventSystem: in KW monitor: [string "return ..."]:13: attempt to index a nil value (global 'domoticz')
Attachments
Untitled1121.jpg
Untitled1121.jpg (41.95 KiB) Viewed 2033 times
Untitled121.jpg
Untitled121.jpg (48.09 KiB) Viewed 2033 times
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: combine power to single sensor

Post by waltervl »

You have to create a dummy device type "Usage (Electric)". Not a counter or electric instant and counter.
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
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: combine power to single sensor

Post by jacobsentertainment »

And the script is in dzvent, forgot to mention.
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

return
{
on =
{
devices =
{
178, 175, 172
}
},

logging =
{
level = domoticz.LOG_ERROR,
marker = 'totaal vermogen',
},

execute = function(dz)
local L1 = dz.devices(178).actualWatt
local L2 = dz.devices(175).actualWatt
local L3 = dz.devices(172).actualWatt
local combinedUsage = dz.devices(214)

local totpower = ( L1 + L2 + L3 )

combinedUsage.update(0,totpower)

dz.log('# totaal vermogen = '..totpower..'')

end
}


i just replace my idx. i creata that dummy Usage(electric). No error now, but no results .
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: combine power to single sensor

Post by waltervl »

This script will count the actual Watt that the solar panels are creating at the moment. So if the solar panels are not working the value will be 0
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

waltervl wrote: Wednesday 20 September 2023 22:13 This script will count the actual Watt that the solar panels are creating at the moment. So if the solar panels are not working the value will be 0

I want to know my consumption. theoretically shouldn't it also work with the consumed value?

i use shelly 3em to monitor consumption. I have no panels, so the production is zero. I thought it could also work for the total energy consumed
thx
Attachments
Untitled11.jpg
Untitled11.jpg (140.52 KiB) Viewed 1981 times
User avatar
jacobsentertainment
Posts: 223
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: combine power to single sensor

Post by jacobsentertainment »

That should also work, what is the log telling you? Go to the log page and typ in the right top corner totaal
(that is stil in you're script)
Also the "last seen time stamp on the new dummy, is this updating?
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

the dummy is time out :D
no error in log.
nothing if i write in search box :totaal
if i make any modification in the sript, in the log apear this :
2023-09-21 12:08:50.815 Status: EventSystem: reset all events...
2023-09-21 12:08:50.816 Status: dzVents: Write file: /home/XXXX/domoticz/scripts/dzVents/generated_scripts/Script #1.lua
Attachments
totaal.jpg
totaal.jpg (51.11 KiB) Viewed 1953 times
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: combine power to single sensor

Post by ssk17051980 »

any idee what to check ?
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: combine power to single sensor

Post by waltervl »

Seems the script is not triggered. So check the devices you configured in the first lines.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest