Real power consumption

Post Reply
olivierf
Posts: 3
Joined: Saturday 04 March 2017 20:53
Target OS: -
Domoticz version:
Contact:

Real power consumption

Post by olivierf » Saturday 04 March 2017 22:28

I was wondering what my actual power consumption was, which was sort of hard to see when my solar panels were generating power (oke not so very difficult but it was tricky to see in the log).

I created a dummy device (measuring watts) and created this LUA script to calculate it.
I don't expect it to be very accurate especially since the power generated by the panels is only updated every 5 minutes or so (solaredge API).

Maybe its useful to someone else :geek:

Code: Select all

    if (devicechanged['Power'] ~= meter) then
        meter = devicechanged['Power']
        --P1 meter uitsplitsen
        power1, power2, power3, power4, power5, power6 = devicechanged['Power']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
        --Zonnepanelen uitsplitsen
        paneelpower = otherdevices_svalues['Zonnepanelen']:match("([^;]+);([^;]+)")
        --Echte verbruik berekenen: verbruik - teruglevering + panelen opbrengst
        stroomverbruik = power5 - power6 + paneelpower
        --En in een dummy device gooien met idx 85
        commandArray[1] = {['UpdateDevice'] = '85|0|' .. stroomverbruik}
    end
 

Abbadon
Posts: 56
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Real power consumption

Post by Abbadon » Monday 06 March 2017 13:28

Hello, can you tell me how to use that lua with 1 device measuring watts? i would like to know what its kWh consuption

25 EMON.Phase.1.Amp 1.0;0.0;0.0 2017-03-06 12:25:46 1.0;0.0;0.0
26 EMON.Phase.2.Amp 1.2;0.0;0.0 2017-03-06 12:25:46 1.2;0.0;0.0
27 EMON.Phase.3.Amp 1.1;0.0;0.0 2017-03-06 12:25:46 1.1;0.0;0.0
28 EMON.Phase.Total 3.3;0.0;0.0 2017-03-06 12:25:46 3.3;0.0;0.0
29 EMON.V.AC 237.150 2017-03-06 12:25:46 237.150
30 EMON.Power 793.2 2017-03-06 12:25:46 793.2
31 EMON.TEMP 23.8 2017-03-06 12:24:42 23.8
95 Power 0;0;0;0;0;0 2017-03-06 12:17:25 0;0;0;0;0;0

olivierf
Posts: 3
Joined: Saturday 04 March 2017 20:53
Target OS: -
Domoticz version:
Contact:

Re: Real power consumption

Post by olivierf » Tuesday 07 March 2017 11:32

Abbadon wrote:Hello, can you tell me how to use that lua with 1 device measuring watts? i would like to know what its kWh consuption

25 EMON.Phase.1.Amp 1.0;0.0;0.0 2017-03-06 12:25:46 1.0;0.0;0.0
26 EMON.Phase.2.Amp 1.2;0.0;0.0 2017-03-06 12:25:46 1.2;0.0;0.0
27 EMON.Phase.3.Amp 1.1;0.0;0.0 2017-03-06 12:25:46 1.1;0.0;0.0
28 EMON.Phase.Total 3.3;0.0;0.0 2017-03-06 12:25:46 3.3;0.0;0.0
29 EMON.V.AC 237.150 2017-03-06 12:25:46 237.150
30 EMON.Power 793.2 2017-03-06 12:25:46 793.2
31 EMON.TEMP 23.8 2017-03-06 12:24:42 23.8
95 Power 0;0;0;0;0;0 2017-03-06 12:17:25 0;0;0;0;0;0
What's your question exactly ?
The device you're listing here does not have a kWh meter. It can be calculated from reading the EMON.Power (very often) but realisticly that wont be very accurate (also I wouldn't know how to do that)

L2v2P
Posts: 19
Joined: Sunday 29 November 2015 10:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P » Tuesday 07 March 2017 13:06

I have implemented more or less the same functionality. However I also wanted to send the energy (kWh) to the dummy device. I do this with this code:

Code: Select all

WhDagConsumptie = WhDagProductie - WhDagExport + WhDagImport
  • WhDagProductie being the energy produced by the solar panels
  • WhDagExport being the energy fed back to the grid
  • WhDagImport being the energy imported from the grid
I then send the power and energy to a dummy device:

Image

However, it functions not quite as expected. If you go to the charts it doesn't log the energy in the first graph, but it does in the second:

Image

Also the all-time counter resets at 00:00 every day. Any idea what the problem might be?

L2v2P
Posts: 19
Joined: Sunday 29 November 2015 10:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P » Tuesday 07 March 2017 15:35

I find this to be quite unusable, especially on days where you have a mix of clouds and sun. I often get negative values for power consumption because the power output of the solar panels has not yet been updated. :(

adjego
Posts: 37
Joined: Monday 16 February 2015 12:42
Target OS: Raspberry Pi
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego » Tuesday 07 March 2017 16:29

When using the API from Solaredge this will never work. That actual power output of the solar panels is at least some minutes behind. I had the same problem when using the API so i switch to measuring it in a different way and created a seperate dummy "smart meter" where i can see the consumption from the panels and from the grid in 1 overview.

L2v2P
Posts: 19
Joined: Sunday 29 November 2015 10:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P » Tuesday 07 March 2017 18:33

adjego wrote:When using the API from Solaredge this will never work. That actual power output of the solar panels is at least some minutes behind. I had the same problem when using the API so i switch to measuring it in a different way and created a seperate dummy "smart meter" where i can see the consumption from the panels and from the grid in 1 overview.
Can you share what you did? Because I don't know how to calculate consumption when my solar panels produce any amount of energy.

adjego
Posts: 37
Joined: Monday 16 February 2015 12:42
Target OS: Raspberry Pi
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego » Thursday 09 March 2017 17:19

So you have the amount of generated power from the solar panels. Next to that you need the power which has been returned and when you calculate "generated power - returned power" you will have the actual consumed power from the solar panels. Then you add the power used from the net and then you have your actual consumed power of that day.

I measure my solar panel output using a z-wave module which reports every minute. Home Energy Meter Gen5

All this data i put in a dummy "Smart Meter" which automatically calculates the amount per day, and in the overview you can see how much came from the Net and how much was used directly from the panels.

Darkblue is from the Net, light blue is directly used from the solarpanels.

Image

L2v2P
Posts: 19
Joined: Sunday 29 November 2015 10:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P » Thursday 09 March 2017 19:15

Ah, so you circumvent the SolarEdge API. Is once every minute accurate enough (as the P1 reports every 10 seconds)?

Toulon7559
Posts: 488
Joined: Sunday 23 February 2014 18:56
Target OS: Raspberry Pi
Domoticz version: latest
Location: Hengelo(Ov)/NL
Contact:

Re: Real power consumption

Post by Toulon7559 » Thursday 09 March 2017 20:11

For clarity and for unambigous information, please apply in the software and the description the correct definitions:
Power is the actual generation and actual consumption, expressed in VA or W(atts)
Energy is the accumulated generation and the accumulated consumption, expressed in kWh. For example over 1 day, over 1 week, 1 month, 1 year, or over the whole lifecycle of registration.

;-) Otherwise it gets confusing .........

Trying to read actual power values from various digital sources such as inverters and from the smartmeter is difficult, because of different intervals and latencies: those read-outs seldomly will be in sync.
Based on experience, I register & display them separately: direct calculation with this values sometimes produces odd results, as described.
If you desire more realistic values, first you will have to filter the registered values, to determine tendencies.
Set1 = RPI-B+RFXCom433+S0PCM+Linksprite-shield for BMP180/DS18B20/RS485+DDS238-1ZN
Set2 = RPI-3+RFLinkGTW+ESP8266s+PWS_WS7000
Common = 3*PVLogger+PWS_TFA_Nexus+KAKUs
=> Energy & Data Management based on Time and on PV&Consumption&Meteo

adjego
Posts: 37
Joined: Monday 16 February 2015 12:42
Target OS: Raspberry Pi
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego » Friday 10 March 2017 9:40

L2v2P wrote:Ah, so you circumvent the SolarEdge API. Is once every minute accurate enough (as the P1 reports every 10 seconds)?
So what i do is that when the data from the solar panels comes in, i use the most recent data from the smart meter. The data from the smartmeter can be max 9 seconds old, which indeed sometimes causes a small Power calculation error, but that's rearly the case.

Image

So calculation the power:

When power consumption is positive, generated power and consumed power are added together.
When power consumption is negative, consumed power is deducted from the generated power.
Toulon7559 wrote:For clarity and for unambigous information, please apply in the software and the description the correct definitions:
Power is the actual generation and actual consumption, expressed in VA or W(atts)
Energy is the accumulated generation and the accumulated consumption, expressed in kWh. For example over 1 day, over 1 week, 1 month, 1 year, or over the whole lifecycle of registration.

;-) Otherwise it gets confusing .........
Sorry for the confusion, but for this dummy smartmeter i use actual total values because this dummy smartmeter does the day calculations himself. No special day values need to be calculated this way. This gives a nice overview of directly used energy from the solarpanels and from the net.

Here you will find my lua code:

Code: Select all

local idxElektraActualConsumption = 213
local idxElektraMinimum = 66
local idxElektraMaximum = 67
local idxElektraTerug = 177

local nrCommands = 1
local zeroValue = 0

commandArray = {}

function Round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

if (devicechanged['Zon']) then
    zonOutput, zonTotal = otherdevices_svalues['Zon']:match("([^;]+);([^;]+)")
    zonOutput = Round(tonumber(zonOutput), 0)
    zonTotal = tonumber(zonTotal)
    zonTotal = zonTotal + 900000
    consumedDal, consumedPiek, returnDal, returnPiek, currentUsage, currentReturn = otherdevices_svalues['Stroom']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
    v1, previousConsumedFromPanel, v3, v4, previousUsage, v6 = otherdevices_svalues['Daadwerkelijke Verbruik']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
    consumedDal = tonumber(consumedDal)
    consumedPiek = tonumber(consumedPiek)
    returnDal = tonumber(returnDal)
    returnPiek = tonumber(returnPiek)
    currentUsage = tonumber(currentUsage)
    currentReturn = tonumber(currentReturn)
    previousConsumedFromPanel = tonumber(previousConsumedFromPanel)
    previousUsage = tonumber(previousUsage)
    consumedTotal = consumedDal + consumedPiek
    returnTotal = returnDal + returnPiek

    currentMinimum = tonumber(otherdevices_svalues['Elektra minimum'])
	currentMaximum = tonumber(otherdevices_svalues['Elektra maximum'])
	currentTerug = tonumber(otherdevices_svalues['Teruglevering'])

    actualConsumedFromPanel = zonTotal - returnTotal
	--print('actualConsumedFromPanel: ' .. actualConsumedFromPanel)
	--print('previousConsumedFromPanel: ' .. previousConsumedFromPanel)
	--print('zonTotal: ' .. zonTotal)
    --print('previousUsage: ' .. previousUsage)
    --print('zonOutput: ' .. zonOutput)
    --print('currentUsage: ' .. currentUsage)
    --print('currentReturn: ' .. currentReturn)
    -- Check what to do when there is generated power.
    if (zonOutput > 0) then
        if (currentUsage > 0) then
            actualCurrentUsage = zonOutput + currentUsage
        elseif (currentReturn >= 0 and zonOutput > currentReturn) then
            actualCurrentUsage = zonOutput - currentReturn
        else
            actualCurrentUsage = previousUsage
        end
    else
            actualCurrentUsage = currentUsage
    end
    
    -- There is no change in my house consumption will be below 30 watt. This will fix any calculation errors.
    if (actualCurrentUsage < 30) then
        actualCurrentUsage = previousUsage
    end    
    -- Because the Z-wave reports power and energy in two steps, sometimes energy did not increase but return did. This is to prevent going back down in consumed energy from panels.
    if (actualConsumedFromPanel < previousConsumedFromPanel) then
        actualConsumedFromPanel = previousConsumedFromPanel
    end
    
    commandArray[nrCommands]={['UpdateDevice'] = idxElektraActualConsumption .. '|0|' .. consumedTotal .. ";" .. actualConsumedFromPanel .. ";" .. zeroValue .. ";" .. zeroValue .. ";" .. actualCurrentUsage .. ";" .. zeroValue}
end
return commandArray

timothee
Posts: 2
Joined: Sunday 24 September 2017 22:44
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Real power consumption

Post by timothee » Tuesday 26 September 2017 20:38

olivierf wrote:
Saturday 04 March 2017 22:28
I was wondering what my actual power consumption was, which was sort of hard to see when my solar panels were generating power (oke not so very difficult but it was tricky to see in the log).

I created a dummy device (measuring watts) and created this LUA script to calculate it.
I don't expect it to be very accurate especially since the power generated by the panels is only updated every 5 minutes or so (solaredge API).

Maybe its useful to someone else :geek:

Code: Select all

    if (devicechanged['Power'] ~= meter) then
        meter = devicechanged['Power']
        --P1 meter uitsplitsen
        power1, power2, power3, power4, power5, power6 = devicechanged['Power']:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
        --Zonnepanelen uitsplitsen
        paneelpower = otherdevices_svalues['Zonnepanelen']:match("([^;]+);([^;]+)")
        --Echte verbruik berekenen: verbruik - teruglevering + panelen opbrengst
        stroomverbruik = power5 - power6 + paneelpower
        --En in een dummy device gooien met idx 85
        commandArray[1] = {['UpdateDevice'] = '85|0|' .. stroomverbruik}
    end
 
Nice work, but I guess you don't make use of a SolarEdge inverter? I'm trying to get something similar (based on another script with partly the same code) working with my SolarEdge inverter, but receiving errors because the inverter only shows the total amount of generated kWh at the Devices page in Domoticz. The actual-/week-/month values are displayed correctly at the Dasbhoard however, so I'm wondering where these values are being calculated or stored.

Has anyone got this kind of calculations working with a SolarEdge inverter (linked through the web API in Domoticz)?

Micha123
Posts: 25
Joined: Monday 28 August 2017 16:44
Target OS: Raspberry Pi
Domoticz version:
Contact:

Post by Micha123 » Saturday 20 January 2018 0:38

I think we need a script, that show only consumpted power in KWh, not actual usage, this dont work if one device (P1 meter) send data every 10 second and the api (SolarEdge) every 5 min.


The onky way is to calculate consumpted power.a script that simply listen when the SolarEdge api send data to domoticz an if it receive data from solaredge api then calculate consupted power

Usage + generated solar energy - returned power.

And if a script do that every time after solarede api refresh/send data to domoticz. Wil be fine, so you can see every 5 min your consupted power @your home.
This wil be best acurate, but if that script calculate it every time after SolarEdge send data, is the data from p1 max 9 second old. I thing its not a big problem by calculate with the consupted power not the actual usage power.

User avatar
McMelloW
Posts: 195
Joined: Monday 20 November 2017 18:01
Target OS: Raspberry Pi
Domoticz version: V3.beta
Location: Harderwijk, NL
Contact:

Re: Real power consumption

Post by McMelloW » Thursday 08 February 2018 17:46

timothee wrote:
Tuesday 26 September 2017 20:38

Has anyone got this kind of calculations working with a SolarEdge inverter (linked through the web API in Domoticz)?
At the end of this topic you can read about reading a SolarEdge Inverter via LAN. I use the perl script sunspec-monitor to get the basic data from my SolarEdge. This in avoiding to use de SolarEdge website API.
All you need is a LAN connection with your SolarEdge Inverter. This document shows how to configure your LAN port on your Inverter. You might also need n update of your firmware. I made one phone call to Solaedge NL support and that was started within 5 minutes.
Below you can see examples of the ouput in json or csv.

Code: Select all

This is the json output.
{
	"timestamp": "2018-02-08 14:14:06",
	"status": "ON (MPPT)",
	"ac_power": 1637,
	"dc_power": 1661,
	"total_production": 207648,
	"ac_voltage": 236.70,
	"ac_current": 6.95,
	"dc_voltage": 377.40,
	"dc_current": 4.40,
	"temperature": 41.70,
	"exported_energy": 0,
	"imported_energy": 0
}

Code: Select all

And the csv output
2018-02-08 15:52:26,ON (MPPT),485,492,209221,236.60,2.12,377.20,1.31,40.49,0,0
Finally, to your question. No,I don't have a working calculation yet. See or the values, you can get from the inverter via LAN provides you enough information you need. The value for ac_power (Watt), is almost the same as ac_voltage * ac_cuurent (Watt). The production/time can easy be calculated by subtracting total_production at the end and the begin of a time interval on the most simple way.

Using the SolarEdge web API, the gererated devices shows other values then what I see the device list in Domoticz. And also different form the values I see at my SolarEdge customer website. The values directly from my inverter do match much more with my SolarEdge customer website and I know there is a time difference in real time from the inverter and displayed at the website.

At this moment I am writing a dzVents script where I use an os.execute('perl sunspec-status ......') to run the perl script. The hardest thing is to understand the use and the working of the Counter type device (RFXmeter, RFX meter counter) and the Energy type device (General, kWh). It is very hard to find any detaled information about what is going underneath the hood of these devices. I hope somebody can explain this to me or point me to some documentation.
Greetings McMelloW

akamming
Posts: 21
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Real power consumption

Post by akamming » Saturday 08 September 2018 11:15

Everyone thanks for the ideas. I created a dzvents script using the ideas in this thread. In no way i want to take credit for the script, because most ideas and pieces of code i found on this forum. I just combined and adjusted to my own needs, however it now works like a charm and since i could not find a fully functioning real power consumption script on this forum, i decided to give something back to the community by posting this script.

prerequisites to make it work
- Sunspec monitor installed on your system. (can be found here https://github.com/tjko/sunspec-monitor)
- Modbus TCP enabled on your solaredge invertor on the default port (instructions can be found here https://www.solaredge.com/sites/default ... l-note.pdf)
- a p1 smart smart meter device
- a virtual electricity device (usage, counter) to store the actual energy output of your inverter
- a virtual electricity device (usage, counter) to store the real power consumption
- a virtual temperature device to store the temperature for the inverter (not needed for real power consumption, so you can remove this part from the code if you like)

and make sure in the code below you change
- the ip adress (should be the one of your inverter).
- possible add a port number with using "-p" to the sunspec monitor (if you used another port number then the default 502 port on the inverter)
- possibly the path to sunspec monitor (depending on how you installed sunspec monitor)
- the names of the devices, so they match the devices in your domoticz system

Sorry for some dutch words in the code. But feel free to change to english and repost :D

Code: Select all

return {
    logging = {
 		level = domoticz.LOG_DEBUG, 			-- Adjust to your needs
 		marker = 'ActualPowerConsumption'
 	},

	on = {
		devices = {
		    'Slimme Meter' -- Name of P1 Smart Meter device 
	    }
	},
	execute = function(domoticz, item)
	    -- Get SolarEdge input using sunspec monitor
	    local handle = io.popen('sunspec-status -m 0 -j 192.168.2.2 || echo error')
        local result = handle:read("*a")
        handle:close()

        -- For debugging purposes: Log result
        domoticz.log ("JSON output Inverter is "..result)
        
        -- Check if we are succesful
        if(result ~= 'error\n') then
            -- no error: declare needed opbjects
		    local SM=domoticz.devices("Slimme Meter") -- P1 Smart Meter Device
		    local SE=domoticz.devices("Zonnepanelen") -- Virtual Electricity device (usage, counter) in which the actual Solar Output will be stored 
		    local SV=domoticz.devices("Stroom Verbruik") -- Virtual Electricity devie (usage, counter) in which the actual power consumption will be stored
		    local OT=domoticz.devices("Omvormer Temperatuur") -- Virtual Temperature device, in which the inverter temperature will be stored

		    local usage=SM.usage
		    local usagedelivered=SM.usageDelivered
		    domoticz.log ("Usage = "..usage ..", Delivered = "..usagedelivered..", P1 cumulative="..SM.usage1+SM.usage2-SM.return1-SM.return2)
		    
            -- convert JSON object to readable format
	        local json = domoticz.utils.fromJSON(result)
	        
	        -- log  timestamp for debugging purposes
	        local Time=require('Time')
	        domoticz.log("Timestamp inverter = "..json.timestamp..", which is "..Time(json.timestamp).secondsAgo.." second(s) ago")
	        
	        -- update SolarEdge virtual sensors
		    domoticz.log("SE.updateElectricity("..json.dc_power..", "..json.total_production..")")
		    SE.updateElectricity(json.dc_power, json.total_production)
		    domoticz.log("OT.updateTemperature("..json.temperature..")")
		    OT.updateTemperature(json.temperature)


            -- calculate real energy consumption
            local virtuelemeterstand=json.total_production+SM.usage1+SM.usage2-SM.return1-SM.return2
            local vermogen=SM.usage-SM.usageDelivered+json.dc_power
            
            -- update real actual usage sensor
            domoticz.log("SV.updateElectricity("..vermogen..","..virtuelemeterstand..")")
            SV.updateElectricity(vermogen,virtuelemeterstand)
        else
        	domoticz.log('failure with io.popen')
        end
	end
}
have fun! let me know if you like it.

1kke
Posts: 3
Joined: Sunday 02 April 2017 10:11
Target OS: NAS (Synology & others)
Domoticz version: V4.9741
Contact:

Re: Real power consumption

Post by 1kke » Monday 15 October 2018 12:09

Hello akamming,

It took a while before I had the script running (I'm running domoticz in a Alpine Docker).
But now everything is fine. It's a great script for measuring the actual powerconsumption.


kr./m.vr.gr.,
1kke

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests