Real power consumption

Moderator: leecollings

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

Real power consumption

Post by olivierf »

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: 40
Joined: Thursday 01 October 2015 8:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland, Wrocław
Contact:

Re: Real power consumption

Post by Abbadon »

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 19:53
Target OS: -
Domoticz version:
Contact:

Re: Real power consumption

Post by olivierf »

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 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P »

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 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P »

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: 11
Joined: Monday 16 February 2015 11:42
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego »

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 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P »

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: 11
Joined: Monday 16 February 2015 11:42
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego »

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 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Real power consumption

Post by L2v2P »

Ah, so you circumvent the SolarEdge API. Is once every minute accurate enough (as the P1 reports every 10 seconds)?
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Real power consumption

Post by Toulon7559 »

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-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
adjego
Posts: 11
Joined: Monday 16 February 2015 11:42
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.5163
Location: Eindhoven
Contact:

Re: Real power consumption

Post by adjego »

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
Micha123
Posts: 62
Joined: Monday 28 August 2017 16:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Post by Micha123 »

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: 427
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: Real power consumption

Post by McMelloW »

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: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Real power consumption

Post by akamming »

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: 5
Joined: Sunday 02 April 2017 10:11
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: NL
Contact:

Re: Real power consumption

Post by 1kke »

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
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Real power consumption

Post by akamming »

Reviving this thread :-)

I just updated to latest beta (4.11290) and i noticed that my virtual device for the real power consumption is not updated on the webpage anymore.

It is only a GUI problem, because when i press F5 in the browser the measurements are there, so the script apparently still works. I tried in chrome, ie and edge. And they all have the same behaviour. Does anyone else experience this problem?

I also noticed the that P1 meter in the GUI now change exactly at the moment i see a logline of the device that the value was changed (nice!), so it looks pretty realtime: Could this be related to the websockets change which was done on the GUI? Anyone have an idea how to fix so the virtual sensors are also updated realtime?
th3snip3r
Posts: 6
Joined: Thursday 08 February 2018 11:06
Target OS: -
Domoticz version:
Contact:

Re: Real power consumption

Post by th3snip3r »

akamming wrote: 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.
Thanks for the script!
Shouldn't AC power being used instead of DC to calculate the real consumption, because this is the power that is released to the 'site'?
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Real power consumption

Post by akamming »

th3snip3r wrote: Monday 23 September 2019 20:22
Shouldn't AC power being used instead of DC to calculate the real consumption, because this is the power that is released to the 'site'?
You're probably right. Never noticed… :o
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Real power consumption

Post by freijn »

The Sunspec script works perfectly here as well.

When implementing the script I found that on a cloudy day the sun goes "off and on" many times which messed up the power consumtion calculation.
As the P1 meter is spitting the output every 3 seconds I have used that update event to trigger the script to retrieve the Solar current and do the calculation as Grid power (-or +) solar power = house consumption.

Sometimes with huge dark clouds I get a mis-reading overall working great.
boskant
Posts: 3
Joined: Wednesday 11 December 2019 10:58
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10717
Location: Boskant
Contact:

Re: Real power consumption

Post by boskant »

Hi olivierf,

I used your code to create my own version of it.
The usage reading of the SM was not working on my side, the reason is unclear to me, maybe because I have a 3 fase meter.
So I created my own usage and delivery.

thanks for your script.

Code: Select all

-- sourse code is from : https://www.domoticz.com/forum/viewtopic.php?t=16440#p224533
-- Modified bcause of faulty reading of P1 values.

----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices


----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Delivery_L1 = 0 -- in Watt hours
Delivery_L2 = 0 -- in Watt hours
Delivery_L3 = 0	-- in Watt hours

Usage_L1 = 0 -- in Watt hours
Usage_L2 = 0 -- in Watt hours
Usage_L3 = 0	-- in Watt hours

CalculatedDelivered = 0     -- in Watt hours
CalculatedUsage = 0         -- in Watt hours

----------------------------------------------------------------------------------------------------------

Debug = "Yes" 		-- Turn debugging on ("YES") or off ("NO")

----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}

local function update(idx, value1, value2)
    local cmd = string.format("%d|0|%.2f;%.2f", idx, value1, value2)
    table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end


if (devicechanged["Slimme Meter"]) then
    
	if not json then
		--print("STATE: Loading JSON")
		json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
	end -- end if : json

	local handle = io.popen('/usr/bin/perl /home/pi/SolarEdge2.perl -m=0 -j 192.168.0.3 || echo error')
    local result = handle:read("*a")
    handle:close()

    -- For debugging purposes: Log result
    if (debug) then
        print ("This is the input from Solaredge "..result)
    end -- end if : Debug
    
    if(result ~= 'error\n') then
        
        -- no error: declare needed opbjects        
        
        -- First convert JSON object to readable format
        local json = json:decode(result)
        
        --data from P1(usage1, usage2, return1, return2, cons, cons)
        usage1, usage2, return1, return2, usage, usageDelivered = otherdevices_svalues["Slimme Meter"]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
	local SE=otherdevices["Zonnepanelen"]           -- Virtual Electricity device (usage, counter) in which the actual Solar Output will be stored 
	local SV=otherdevices["Stroom Verbruik"]        -- Virtual Electricity device (usage, counter) in which the actual power consumption will be stored
	local OT=otherdevices["Omvormer Temperatuur"]   -- Virtual Temperature device, in which the inverter temperature will be stored
        local Delivery_L1 = otherdevices["Delivery L1"] -- Delivered power in Fase L1 created by P1 meter
	local Delivery_L2 = otherdevices["Delivery L2"] -- Delivered power in Fase L2 created by P1 meter
        local Delivery_L3 = otherdevices["Delivery L3"] -- Delivered power in Fase L3 created by P1 meter

        local Usage_L1 = otherdevices["Usage L1"]       -- Used power in Fase L1 created by P1 meter
	local Usage_L2 = otherdevices["Usage L2"]       -- Used power in Fase L2 created by P1 meter
        local Usage_L3 = otherdevices["Usage L3"]       -- Used power in Fase L3 created by P1 meter
        
        CalculatedDelivered=Delivery_L1+Delivery_L2+Delivery_L3
        CalculatedUsage=Usage_L1+Usage_L2+Usage_L3

        -- For debugging purposes: Log result
        if (debug) then
	        print ("SM.usage1 = "..usage1.." SM.usage2 = "..usage2.." SM.return1 = "..return1.." SM.return2 = "..return2.." Current Power Usage = "..usage.." Current Power Delivery = "..usageDelivered)
	        print ("Usage L1 = "..Usage_L1.." Usage L2 = "..Usage_L2.." Usage L3 = "..Usage_L3.." Usage L1+L2+L3 = "..CalculatedUsage)
	        print ("Delivery L1 = "..Delivery_L1.." Delivery L2 = "..Delivery_L2.." Delivery L3 = "..Delivery_L3.." Total L1+L2+L3 = "..CalculatedDelivered)
	        print ("Total Solar Production = "..json.total_production.." Current Solar Power = "..json.ac_power)
	end -- end if : Debug


        -- log  timestamp for debugging purposes
        --local Time=require('Time') 
        --print ("Timestamp inverter = "..json.timestamp..", which is "..Time(json.timestamp).secondsAgo.." second(s) ago")
        
        -- update SolarEdge virtual sensors
        print ("Zonnepanelen("..json.ac_power..", "..json.total_production..")")
        update(otherdevices_idx["Zonnepanelen"],json.ac_power,json.total_production)
        print ("Omvormer Temperatuur("..json.temperature..")")
        update(otherdevices_idx["Omvormer Temperatuur"],json.temperature,0)

        -- calculate real energy consumption
        local virtuelemeterstand=json.total_production+usage1+usage2-return1-return2
        --local vermogen=usage-usageDelivered+json.ac_power
        local vermogen=CalculatedUsage-CalculatedDelivered+json.ac_power
            
        -- update real actual usage sensor
        print("Stroom Verbruik("..vermogen..","..virtuelemeterstand..")")
        update(otherdevices_idx["Stroom Verbruik"],vermogen,virtuelemeterstand)

    end -- end if : result

 
end --end if : devicechanged

return commandArray

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest