PowerUsage, and return values without a P1 meter

Moderator: leecollings

Post Reply
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

PowerUsage, and return values without a P1 meter

Post by gajotnt »

Hello, i recently adquired some solar panels, and sometimes i give power to the grid (the power company doesnt buy), since i have a pzem004T sensor (connected to a sonoff basic with Tasmota) that only knows one direction, when im giving 300w to the grid it show has 300w consumption.
I ordered a SDM120 that can see both directions, but since i havent received the SDM120 sensor, im guessing it will give negative values when im giving power to the grid.

Is there any way to:
- set the negative values to Zero
- Send the negative values to another virtual sensor, so that i can know how mutch im wasting.
- (or) like the (i think) the P1 hardware shows usage and return on the graphs.
Power usage, with negative values, due to sending power to the grid
Power usage, with negative values, due to sending power to the grid
Screenshot 2018-07-06 14.43.29-Recovered.jpg (86.62 KiB) Viewed 2654 times
Last edited by gajotnt on Friday 13 July 2018 17:52, edited 1 time in total.
Toulon7559
Posts: 849
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by Toulon7559 »

For getting pulses from the S0-interface of a kWh-meter while measuring consumption, you would wire the SDM120C as drawn on the connection diagram provided with your SDM120C: load-to-loadinterface + grid-to-gridinterface.
For getting pulses from the S0-interface of a kWh-meter during PV-production, you have to connect it 'in reverse' (= grid-to-loadinterface and inverter-to-gridinterface).
In the Wiki you get info to read out the RS485-interface of SDM120C, which online provides you with much more data/info.
As described above, for 'normal' wiring you are right that 'delivery to grid' will be negative, but if you 'reversely' wire, obviously 'delivery to grid' will become positive.
;-) But you have to carefully check in the script!
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.
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

Ok, but is there anyway of creating two virtual meters:

- One that only displays the positive values (So that i have an accurate reading of what im consuming, by deleting the negative and showing it has zero)
- Another that displays only the negative values (so that i know how much energy im wasting by giving it to the network)
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by markk »

I collect my generation data from the panels and my energy consumption then use this method to upload the data to PVOutput.org: http://www.domoticz.com/wiki/Upload_ene ... o_PVoutput

PV Output then calculates the export figures from the data I’ve provided and it is all stored there.
7F690EE0-6F7F-4E16-88F2-DC6A4114AF74.png
7F690EE0-6F7F-4E16-88F2-DC6A4114AF74.png (142.04 KiB) Viewed 2685 times
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

Thanks, will look into this :)
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

I did the Math, just dont know how to program it -.-

Things I know:
- Solar energy being generated;
- Energy Consumption/return of/to the grid;

So if:
Example: if solar being generated is 600w, and im returing 100w (gives a negative value) to the grid

SOLAR + (EnergyUsed/Returned) = Consumption

Then i know that the house is using 500w:
600 + (-100) = 500w (being consumed by the house)

So then I can calculate the amount im losing (by returing it to the grid)

SOLAR - Consumption = "Waste"
Using the example:
600 - 500 = 100w (of "wasted energy")

Now if its night time, this would not work correctly, so any negative values would have to be set to zero? or discarded?, because the idea of the "wasted energy counter" would be to see how to better use and know how much money is being wasted by sending it to the grid.
because:
If SOLAR = 0 and Consumption= 500w
0 - 500 = -500w

Can anyone give some insight
I guess this code would work for calculating the Consumption part:

Code: Select all

-- demo time script

-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t");  -- sets up currentDate.[table] 
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec

function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

commandArray = {}

TotalPowerUsage, TotalEnergyUsage = otherdevices_svalues["Total"]:match("([^;]+);([^;]+)")

SolarPowerUsage, SolarEnergyUsage = otherdevices_svalues["Solar"]:match("([^;]+);([^;]+)")

CurrentPowerBalance = SolarPowerUsage + TotalPowerUsage
CurrentEnergyBalance = SolarEnergyUsage + TotalEnergyUsage

update("Consumption", 50, CurrentPowerBalance, CurrentEnergyBalance, 2) -- 50 is the ID of the dummy consumption device


return commandArray

Calculating the "waste" part im stuck :(

above script taken from here: viewtopic.php?t=18705
And simplified
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

Think i got it working :D

To whom it may help:

Power cunsumption of the house taking into consideration the Solar Power generated

Code: Select all

--Calculate what the house is consuming
-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t");  -- sets up currentDate.[table] 
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec

function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

commandArray = {}

-- Total consumption of the house, when positive its consuming from grid, when negative its giving to the grid
-- Solar is self explanatory

TotalUsage, TotalEnergyUsage = otherdevices_svalues["Total"]:match("([^;]+);([^;]+)")
SolarPowerUsage, SolarEnergyUsage = otherdevices_svalues["Solar"]:match("([^;]+);([^;]+)")

-- The logic here is to know and have easy access to the real value of power consumption, so if my Solar panels are giving 600watts and the Total is showing -150watts,
-- means that the house is consuming 450watts and i'm giving 150watts to the grid for free. 
-- So that value is calculated bellow.

ConsumoPowerBalance = SolarPowerUsage + (TotalPowerUsage)
ConsumoEnergyBalance = SolarEnergyUsage + (TotalEnergyUsage)

update("Consumo", 94, ConsumoPowerBalance, ConsumoEnergyBalance, 2) -- 94 is the ID of the dummy incoming device
end

return commandArray
Now to calculate only the "wasted" energy:

Code: Select all

-- Calculate Wasted Energy
-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t");  -- sets up currentDate.[table] 
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec

function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

commandArray = {}

-- Now to do this we only need the negative values

TotalPowerUsage, TotalEnergyUsage = otherdevices_svalues["Total"]:match("([^;]+);([^;]+)")

-- So if the Total Power usage is bellow zero, it records the value to the dummy waste device (and passes it to positive)
if tonumber(TotalPowerUsage) <=0  then
WastePowerBalance = -(TotalPowerUsage)
WasteEnergyBalance = -(TotalEnergyUsage)
end

-- If it's a positive number it will record the value has Zero, since it's not wasted energy
if tonumber(ConsumoPowerUsage) >=1  then

WastePowerBalance = 0
WasteEnergyBalance = 0
end

update("Waste", 94, WastePowerBalance, WasteEnergyBalance, 2) -- 94 is the ID of the dummy incoming device


return commandArray
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by simon_rb »

Hey,

These scripts look perfect for my setup however I am having trouble getting them to work.. I'll explain my setup.

I have 3 x OWL devices sending over data,
1) House Energy Usage - This is what the house consumes
2) Solar PV Generation - This is what the Solar Panels are producing
3) Zappi EV Charger - This is connected to the feed that chargers the car.. This is not a factor here.

I would like to see how much I borrow from the Grid and how much I waste sending it to the Grid. I have a dummy energy meter called National Grid. This is what I would like to update to when the Solar Panels (Solar PV Generation) isn't producing enough. So that would be Solar PV Generation - House Energy Usage.. If this is positive then it can be updated to the "Wasted" Energy meter (Which I haven't made yet). If is a positive negative figure then I'd like to update the National Grid meter as we are now barring from the grid.. I hope that makes sense. I tried your script and I get the following error:-

2018-09-01 18:54:32.934 Error: EventSystem: in Grid 3: [string "--Calculate what the house is consuming..."]:28: <eof> expected near 'end'

Any help would be much appreciated!!!

Code: Select all

--Calculate what the house is consuming
-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t");  -- sets up currentDate.[table] 
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec

function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end 

commandArray = {}

-- Total consumption of the house, when positive its consuming from grid, when negative its giving to the grid
-- Solar is self explanatory

TotalUsage, TotalEnergyUsage = otherdevices_svalues["House Energy Usage"]:match("([^;]+);([^;]+)")
SolarPowerUsage, SolarEnergyUsage = otherdevices_svalues["Solar PV Generation"]:match("([^;]+);([^;]+)")

-- The logic here is to know and have easy access to the real value of power consumption, so if my Solar panels are giving 600watts and the Total is showing -150watts,
-- means that the house is consuming 450watts and i'm giving 150watts to the grid for free. 
-- So that value is calculated bellow.

ConsumoPowerBalance = SolarPowerUsage + (TotalPowerUsage)
ConsumoEnergyBalance = SolarEnergyUsage + (TotalEnergyUsage)

update("National Grid", 776, ConsumoPowerBalance, ConsumoEnergyBalance, 2) -- 94 is the ID of the dummy incoming device
end

return commandArray
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by simon_rb »

Ok, I have managed to get something working which includes wasted energy (exported back to grid and not used). The instant wattage works but I just would love to get the total consumption for the day for each of the two dummy meters (National Grid & Wasted). At the mo it is only adding the total difference to the day and I'd rather them add the totals up as they get the values.

Does that make sense? I don't want the total for the day of the Solar and House usage minus each other than added to the tow dummy meters (National Grid & Wasted). Maybe set Domoticz to work it out?

Please help as I am completed stuck.

Please forgive the poor code below, it needs to be cleaned and it is hacked together pinching code from other great scripts users have created.

Many Thanks

Code: Select all


-- demo time script

-- Set printing to log options (true / false)
printData = true
-- printData = false						-- writes execution information to the log for script performance information
-- printDebug = false						-- writes detailed information for fault finding purposes
 printDebug = false

-- Get current date & time
t1 = os.time()
local currentDate = os.date("*t");  -- sets up currentDate.[table] 
-- (currentDate.year [full], .month [1-12], .day [1-31], .hour [0-23], .min [0-59], .sec [0-59], .wday [0-6 {Sun-Sat}])
sCurrentTime = currentDate.year .. "-" .. currentDate.month .. "-" .. currentDate.day .. " " .. currentDate.hour .. ":" .. currentDate.min .. ":" .. currentDate.sec

function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
--commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ; }
end 


commandArray = {}



SolarPowerGeneration, SolarEnergyGeneration = otherdevices_svalues["Solar PV Generation"]:match("([^;]+);([^;]+)")

if printDebug == true then
	print(" ----- SolarPowerGeneration = " .. SolarPowerGeneration .. " W");
	print(" ----- SolarEnergyGeneration = " .. SolarEnergyGeneration .. " Wh");
end

MainCUPowerUsage, MainCUEnergyUsage = otherdevices_svalues["House Energy Usage"]:match("([^;]+);([^;]+)")

if printDebug == true then
	print(" ----- MainCUPowerUsage = " .. MainCUPowerUsage .. " W");
	print(" ----- MainCUEnergyUsage = " .. MainCUEnergyUsage .. " Wh");
end

NationalPowerUsage, NationalEnergyUsage = otherdevices_svalues["National Grid"]:match("([^;]+);([^;]+)")

if printDebug == true then
	print(" ----- NationalPowerUsage = " .. NationalPowerUsage .. " W");
	print(" ----- NationalEnergyUsage = " .. NationalEnergyUsage .. " Wh");
end

--GardenCUPowerUsage, GardenCUEnergyUsage = otherdevices_svalues["Zappi EV Charger"]:match("([^;]+);([^;]+)")

--if printDebug == true then
--print(" ----- GardenCUPowerUsage = " .. GardenCUPowerUsage .. " W");
--print(" ----- GardenCUEnergyUsage = " .. GardenCUEnergyUsage .. " Wh");
--end

-- Do the calculations
-- CurrentPowerBalance = SolarPowerGeneration - (MainCUPowerUsage + GardenCUPowerUsage)
-- CurrentEnergyBalance = SolarEnergyGeneration - (MainCUEnergyUsage + GardenCUEnergyUsage)
CurrentPowerBalance = MainCUPowerUsage - SolarPowerGeneration
--CurrentEnergyBalance = MainCUEnergyUsage - SolarEnergyGeneration
CurrentEnergyBalance = MainCUEnergyUsage - SolarEnergyGeneration

--HousePower = (MainCUPowerUsage + GardenCUPowerUsage)
--HouseEnergy = (MainCUEnergyUsage + GardenCUEnergyUsage)
HousePower = (CurrentPowerBalance)
HouseEnergy = (CurrentEnergyBalance)
HousePowerN = 0
HouseEnergyN = 0.00
WastePowerBalanceN = 0
WasteEnergyBalanceN = 0


if printDebug == true then	
	print(" ----- CurrentPowerBalance = " .. CurrentPowerBalance .. " W");
	print(" ----- CurrentEnergyBalance = " .. CurrentEnergyBalance .. " Wh");
end

if printData == true then	

	if CurrentPowerBalance <0 then
	print("FREE Electric - Whoop!    " .. CurrentPowerBalance .. "W");
	WastePowerBalance = -(CurrentPowerBalance)
    WasteEnergyBalance = -(CurrentEnergyBalance)
	update("National Grid", 784, HousePowerN, HouseEnergyN, 2) -- 784 is the ID of dummy house consumption device
	update("Wasted", 785, WastePowerBalance, WasteEnergyBalance, 2)
	else
	   update("National Grid", 784, HousePower, HouseEnergy, 2) -- 784 is the ID of dummy house consumption device
	   update("Wasted", 785, WastePowerBalanceN, WasteEnergyBalanceN, 2)
	   
end
end


	

   

return commandArray
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

Hello, sorry for not replying earlier, did not notice your post.

Yes i understand what you are saying, but i also have the same problem with dummy counters not calculating the usage properly :/
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by simon_rb »

gajotnt wrote: Monday 03 September 2018 18:04 Hello, sorry for not replying earlier, did not notice your post.

Yes i understand what you are saying, but i also have the same problem with dummy counters not calculating the usage properly :/
No worries dude :D

I just checked that script above and it does not work. Maybe I need to split them into two difference scripts.
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

So the only real data you have is the "House" meter right?
And when its negative you want it to update one new dummy meter, and when its positive to update another, right?
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: PowerUsage, and return values without a P1 meter

Post by gajotnt »

Check this dzvents script to calculate the wasted power and energy


viewtopic.php?f=59&t=24620&p=190649#p190649
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests