multiply kWh value

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:

multiply kWh value

Post by jacobsentertainment »

Hi all,

I got an script running for my heating system and the amount of energy that i put in is determined by the value of the kWh that is available of the solar panels. I would like to add something to the script to increase this value by a percentage
Full script in use (works fine)
Spoiler: show
return {
on = {
devices = {
260
},
},

logging = {
level = domoticz.LOG_INFO,
marker = "Boiler verwarming"
},
execute = function(domoticz, devices)
local Inverter = domoticz.devices(260)
local Kwh = Inverter.actualWatt
local Boiler_tempT = domoticz.devices(250) -- gem temp boiler totaal
local Temp_BT = Boiler_tempT.temperature

local Boil1 = domoticz.devices(219) --2000watt links
local Boil2 = domoticz.devices(220) --2000watt links
local Boil3 = domoticz.devices(221) --1500watt links
local Boil4 = domoticz.devices(222) --1500watt links

local Boil5 = domoticz.devices(223) --1500watt rechts
local Boil6 = domoticz.devices(224) --1500watt rechts
local Boil7 = domoticz.devices(225) --2000watt rechts
local Boil8 = domoticz.devices(226) --2000watt rechts


if Temp_BT >= 85 or Temp_BR >= 85 or Kwh <= 1000 then --off
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 1000 and Kwh <= 1500) and Temp_BT <= 85 then --1
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 1500 and Kwh <= 2000) and Temp_BT <= 85 then --2
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 2000 and Kwh <= 3500) and Temp_BT <= 85 then --3
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 3500 and Kwh <= 4000) and Temp_BT <= 85 then --4
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 4000 and Kwh <= 4500) and Temp_BT <= 85 then --5
Boil1.switchOn().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOn().checkFirst()
elseif (Kwh >= 4500 and Kwh <= 5000) and Temp_BT <= 85 then --6
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 5000 and Kwh <= 5500) and Temp_BT <= 85 then --7
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOn().checkFirst()
elseif (Kwh >= 5500 and Kwh <= 6000) and Temp_BT <= 85 then --8
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOn().checkFirst()
elseif (Kwh >= 6000 and Kwh <= 6500) and Temp_BT <= 85 then --9
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 6500 and Kwh <= 7000) and Temp_BT <= 85 then --10
Boil1.switchOff().checkFirst()
Boil2.switchOff().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 7000 and Kwh <= 7500) and Temp_BT <= 85 then --11
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 7500 and Kwh <= 8000) and Temp_BT <= 85 then --12
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOn().checkFirst()
elseif (Kwh >= 8000 and Kwh <= 8500) and Temp_BT <= 85 then --13
Boil1.switchOn().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOff().checkFirst()
Boil5.switchOff().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOn().checkFirst()
elseif (Kwh >= 8500 and Kwh <= 9000) and Temp_BT <= 85 then --14
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 9000 and Kwh <= 10000) and Temp_BT <= 85 then --15
Boil1.switchOn().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOff().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOff().checkFirst()
Boil7.switchOn().checkFirst()
Boil8.switchOff().checkFirst()
elseif (Kwh >= 10000 and Kwh <= 12000) and Temp_BT <= 85 then --16
Boil1.switchOff().checkFirst()
Boil2.switchOn().checkFirst()
Boil3.switchOn().checkFirst()
Boil4.switchOn().checkFirst()
Boil5.switchOn().checkFirst()
Boil6.switchOn().checkFirst()
Boil7.switchOff().checkFirst()
Boil8.switchOn().checkFirst()
end
end
}
My plan is to have some simple number in the script to multply the value of the Kwh, but I tried this and this doesn't work.

Code: Select all

            local Inverter = domoticz.devices(260)
                local Kwh = Inverter.actualWatt + 30%
How can I get this to work?
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: multiply kWh value

Post by waltervl »

To add 30 percent I usually multiply with 1.3

Code: Select all

local Inverter = domoticz.devices(260)
local Kwh = Inverter.actualWatt*1.3
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: multiply kWh value

Post by jacobsentertainment »

:oops: so simple that I couldn't think of that. Thanks that works fine!
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: multiply kWh value

Post by jacobsentertainment »

Now I'm trying to have this in a other setup, as soon as I have full power of the panels I dont need to add power of the grid, so when its below a value I want to add some power of the grid etc. But this won't work ;) Any suggestion here :mrgreen:

Code: Select all

return {
        on = {
          devices = {
            260
        },
    },
    
    	logging = {
        level = domoticz.LOG_INFO,
        marker = "Boiler verwarming"
    },
        execute = function(domoticz, devices)
       local Inverter = domoticz.devices(260)
            local Kwh = Inverter.actualWatt

        
        if Kwh >= 10 and Kwh <= 4000 then 
            domoticz.devices(275).updateEnergy((actualWatt)*1.5)
        elseif
            Kwh >= 4000 and Kwh <= 6000 then 
                domoticz.devices(275).updateEnergy((actualWatt)*1.3)
                elseif
                    Kwh >= 6000 then 
                        domoticz.devices(275).updateEnergy(actualWatt)
                        
        end
end
}
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: multiply kWh value

Post by waltervl »

add some logging to show what Kwh is.
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: multiply kWh value

Post by jacobsentertainment »

This is data coming from the growatt inverter.

Code: Select all

    Allemaal
    Status
    Probleem

	Filter: X
2022-10-25 16:30:39.272 Growatt: Login Succesfull
2022-10-25 16:30:39.272 Growatt: Plant ID: 1490627 was found
2022-10-25 16:30:39.378 Growatt: Currently producing: 631.6 Watt. Totall produced: 679.8 kWh in Wh that is: 679800.0
2022-10-25 16:30:39.391 Growatt: Update 0:'631.6;679800.0' (Growatt - Inverter (kWh))
2022-10-25 16:30:39.406 Growatt: Update 0:'631.6' (Growatt - Inverter (W))
2022-10-25 16:30:39.635 Status: dzVents: Info: Handling events for: "Growatt - Inverter (W)", value: "631.6"
2022-10-25 16:30:39.635 Status: dzVents: Info: Boiler verwarming: ------ Start internal script: Boiler verwarming: Device: "Growatt - Inverter (W) (Growatt)", Index: 260 
(some background info)
I use this to power my heating system. So at this moment I use all the power of the panels rounded down for heating, but the temperature is dropping and the sun power to so I want to add some power of the grid because that's cheaper then gas. So but when the panels are giving full output I don't want to add power of the grid, only in the lower power zone (so to say) so if the power from the panels is between 0 and 4kW add 50% and is its between 4kW and 6kW add 30% and above nothing.
So instead of changing any on the growatt plugin I just make a new dummy thats updated with above values and from there the power is regulated.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest