This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Energy calculation and data saving
#1
Dear all,
I manage some energy counters (energy produced by photovoltaic, energy sold to the network) and in the meanwhile I calculate the self-consumption energy. Daily and total. Here below is shown the script I did and I would like to ask you if there's a best way to improve it.

The system works fine but I would like to know if there's a better way to manage this process.

1. Scheduled script to read the value of energy instrument at the beginning of the day (energy counter of instrument cannot be reset). Hence I find this method to obtain daily data.

Code:
-- script run every day at 0:0 am.
-- script to get value from instrument of photovoltaic energy and energy sold.

evenduta = grp.getvalue('3/4/16') -- read from the instrument value of energy sold

grp.write('32/1/10', evenduta) -- write to morning_energy_sold which has address 32/1/10

-- evenduta_mattino = grp.getvalue('32/1/10')

ftv = grp.getvalue('3/4/28') -- read from the instrument value of energy produced by photovoltaic
grp.write('32/1/11', ftv) -- write to morning_energy_photovoltaic which has address 32/1/11

2. Scheduled script to calculate energy product by photovoltaic and self-consumption energy.


Code:
-- script runs every day, every hour at 59 minutes
-- script to calculate the daily energy product by photovoltaic and self-consumption energy. The last script of the day will give the result of the day.

ftv = grp.getvalue('3/4/28') -- energy read by instrument of photovoltaic.
ftv_mattino = grp.getvalue('32/1/11') -- photovoltaic energy read by morning script.

evenduta = grp.getvalue('3/4/16') -- energy read by instrument of energy sold.
evenduta_mattino = grp.getvalue('32/1/10') -- energy-sold read by morning script.

delta_ftv = ftv - ftv_mattino -- difference to calculate daily photovoltaic energy.
delta_evenduta = evenduta - evenduta_mattino -- difference to calculate daily energy sold.

grp.write('32/1/12', delta_ftv)
grp.write('32/1/13', delta_evenduta)

energia_autoconsumata = delta_ftv - delta_evenduta -- difference to calculate self-consumption energy

grp.write('32/1/15', energia_autoconsumata) -- daily value of self-consumption energy

autoconsumo_perc = (energia_autoconsumata / delta_ftv) * 100 -- % value of daily self-consumption energy

grp.write('32/1/14', autoconsumo_perc)


3. Scheduled script to calculate the total self-consumption energy.
Code:
-- script runs all days, at 11 pm at 59 minutes.
-- script to calculate total self-consumption energy.

daily = grp.getvalue('32/1/15') -- read daily self-consumption energy

os.sleep(2)

total = storage.get('autoconsumo_totale') -- get from system self-consumption energy

os.sleep(2)

total = daily + total -- add to total the daily value

os.sleep(2)

grp.write('32/1/16', total) -- write to "Total self-consumption energy" address

storage.set('autoconsumo_totale', total) -- save on system new "Total self-consumption energy"

Thanks.

BR
Reply


Messages In This Thread
Energy calculation and data saving - by Domoticatorino - 28.04.2021, 15:11

Forum Jump: