Fewer no grid charge months

This commit is contained in:
Aart van Halteren
2022-01-10 22:27:25 +01:00
parent 8725c12a68
commit 28a806f584
2 changed files with 9 additions and 7 deletions

View File

@@ -3,8 +3,8 @@ EASY_ENERGY_TARIFFS = {}
class Cost
attr_reader :battery, :max_charge_kwh, :entsoe
attr_accessor :max_charge_kwh
attr_reader :battery, :entsoe
def initialize(battery_capacity=10.0, max_charge=5.0)
@entsoe = Entsoe.new
@@ -161,8 +161,8 @@ class Cost
# charge battery with return_kwh
return_kwh -= battery.charge(return_kwh)
if lowest_hour.eql?(formatted_hour) # lowest_hour = "" if small difference between high/low
# charge battery during lowest hour
if (lowest_hour.eql?(formatted_hour) || entsoe.price_at(formatted_hour) < 0) # lowest_hour = "" if small difference between high/low
# charge battery during lowest hour, or when prices are negative
usage_kwh += battery.charge(max_charge_kwh)
else
# if during expensive hours || more than <max_charge_kwh> kwh then discharge_battery
@@ -197,7 +197,7 @@ class Cost
oxxio_rate,
oxxio_cost]
p "%s,%s,%s,%s,%s,%s,%s,%03f,%s,%s,%s,%s,%s" % (one_hour[0..7] + one_hour[8..12].map{|c| format_cost(c)})
p "%s,%s,%s,%s,%s,%s,%s,%0.02f,%s,%s,%s,%s,%s" % (one_hour[0..7] + one_hour[8..12].map{|c| format_cost(c)})
result << one_hour
hour_start = hour_start.advance(:hours => 1)

View File

@@ -10,12 +10,14 @@ class Entsoe
URL = 'https://transparency.entsoe.eu'
attr_accessor :no_grid_charge_months
attr_reader :storage_cost
def initialize(api_key = "c2287e07-0c26-4950-b430-22b7f75a8f2e")
@api_key = api_key
@kwh_prices = {}
@storage_cost = 0.05 # how much does it cost to store 1 kwh in battery
@no_grid_charge_months = [5,6,7] # months where we assume there is enough surplus from sun power
end
def price_at(formatted_hour)
@@ -42,8 +44,8 @@ class Entsoe
sorted_prices = prices_at(date).to_a.sort_by(&:last) # sort according to price
highest_hour = sorted_prices.last[0]
# From Apr-Oct: do not charge; every hour that has cost > 0 is a high_hour
if [4,5,6,7,8,9,10].include?(date.month)
# Some months: do not charge; every hour that has cost > 0 is a high_hour
if @no_grid_charge_months.include?(date.month)
lowest_hour = "" # effectively no charging from grid
high_hours = sorted_prices.select{|p| p[1] > 0}.to_h.keys
else