From adb2e38efa5be63d7da9f10684c8f5590c9e6ff6 Mon Sep 17 00:00:00 2001 From: Aart van Halteren Date: Mon, 10 Jan 2022 20:16:58 +0100 Subject: [PATCH] No charging at some days --- app/models/cost.rb | 7 ++++--- app/models/entsoe.rb | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/cost.rb b/app/models/cost.rb index cc70b2d..1a436a7 100644 --- a/app/models/cost.rb +++ b/app/models/cost.rb @@ -161,12 +161,13 @@ class Cost # charge battery with return_kwh return_kwh -= battery.charge(return_kwh) - if lowest_hour.eql?(formatted_hour) + if lowest_hour.eql?(formatted_hour) # lowest_hour = "" if small difference between high/low # charge battery during lowest hour usage_kwh += battery.charge(max_charge_kwh) else # if during expensive hours || more than kwh then discharge_battery - if (battery.battery_kwh > max_charge_kwh) || high_hours.include?(formatted_hour) + # if (battery.battery_kwh > max_charge_kwh) || high_hours.include?(formatted_hour) + if high_hours.include?(formatted_hour) usage_kwh -= battery.discharge(usage_kwh) end end @@ -196,7 +197,7 @@ class Cost oxxio_rate, oxxio_cost] - p "%s,%s,%s,%s,%s,%s,%s,%s,%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,%03f,%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) diff --git a/app/models/entsoe.rb b/app/models/entsoe.rb index d5f5092..394b03a 100644 --- a/app/models/entsoe.rb +++ b/app/models/entsoe.rb @@ -20,6 +20,7 @@ class Entsoe def price_at(formatted_hour) unless @kwh_prices.key?(formatted_hour) + p "Fetching Entsoe tariffs for %s" % formatted_hour @kwh_prices.merge!(query_day_ahead_prices(Date.parse(formatted_hour))) end @kwh_prices[formatted_hour] @@ -45,6 +46,10 @@ class Entsoe charge_rate = sorted_prices.first[1] # assume we charge at lowest hour high_hours = sorted_prices.select{|p| p[1] > charge_rate + storage_cost}.to_h.keys + # reset lowest_hour (effectively not charging), when price difference smaller than storage_cost + highest_price = sorted_prices.last[1] + lowest_hour = "" if (highest_price-charge_rate) < storage_cost + return lowest_hour,highest_hour,high_hours end