Latest tarif info added

This commit is contained in:
Aart van Halteren
2022-09-15 18:51:45 +02:00
parent a55c6ba736
commit 038b02350d
2 changed files with 62 additions and 25 deletions

View File

@@ -1,34 +1,51 @@
require 'open-uri'
EASY_ENERGY_TARIFFS = {}
# See https://www.belastingdienst.nl/wps/wcm/connect/bldcontentnl/belastingdienst/zakelijk/overige_belastingen/belastingen_op_milieugrondslag/tarieven_milieubelastingen/tabellen_tarieven_milieubelastingen
# Without VAT
ENERGY_TAX_KWH = { 2020 => 0.09770, 2021 => 0.09428, 2022 => 0.03679}
ODE_KWH = { 2020 => 0.0273, 2021 => 0.0300, 2022 => 0.0305}
# merge by adding values
TAX_KWH = ENERGY_TAX_KWH.merge(ODE_KWH){|key, energy_tax, ode| energy_tax + ode}
class Cost
attr_accessor :max_charge_kwh
attr_reader :battery, :entsoe
def initialize(battery_capacity=10.0, max_charge=5.0, storage_cost=0.05)
@entsoe = Entsoe.new(storage_cost)
def initialize(zone="Amsterdam", battery_capacity=10.0, max_charge=5.0, storage_cost=0.05)
@entsoe = Entsoe.new(zone, storage_cost)
@max_charge_kwh = max_charge
@battery = Battery.new(battery_capacity)
end
# Government reduced VAT to 9% from 1 July 2022 until 31 Dec 2022
def vat_at(date)
jul22 = Date.parse("2022-09-01")
dec22 = Date.parse("2022-12-31")
if (date >= jul22 && date <= dec22)
0.09
else
0.21
end
end
def format_cost(cost)
cost ? "EUR %0.03f" % cost : "EUR ?"
end
# Assume: usage_kwh_cost, return_kwh_cost already includes vat
def add_tax(formatted_hour,usage_kwh,usage_kwh_cost,return_kwh, return_kwh_cost)
return nil if (usage_kwh.nil? || usage_kwh_cost.nil? || return_kwh.nil? || return_kwh_cost.nil?)
vat = 1 + vat_at(Date.parse(formatted_hour))
year = Date.parse(formatted_hour).year
case year
when 2020
usage_kwh * (usage_kwh_cost + 0.11822 + 0.03303) - return_kwh * (return_kwh_cost + 0.11822 + 0.03303)
when 2021
# see https://www.vastelastenbond.nl/blog/overzicht-energiebelasting-en-ode-2021-2022-en-je-energierekening-2021/
usage_kwh * (usage_kwh_cost + 0.11408 + 0.03630) - return_kwh * (return_kwh_cost + 0.11408 + 0.03630)
when 2022
usage_kwh * (usage_kwh_cost + 0.04452 + 0.03691) - return_kwh * (return_kwh_cost + 0.04452 + 0.03691)
end
# calculate tax per kwh - which the sum of energy_tax and ode
tax = TAX_KWH[year]*vat
usage_kwh * (usage_kwh_cost + tax) - return_kwh * (return_kwh_cost + tax)
end
######################################################
@@ -110,15 +127,34 @@ class Cost
def oxxio_energy_cost(formatted_hour, normaal_kwh, dal_kwh, year_shift=0)
return nil if (normaal_kwh.nil? || dal_kwh.nil?)
year = Date.parse(formatted_hour).year+year_shift
case year
when 2020
normaal_kwh * (0.07865 + 0.11822 + 0.03303) + dal_kwh * (0.06215 + 0.11822 + 0.03303)
when 2021
normaal_kwh * (0.06782 + 0.11408 + 0.03630) + dal_kwh * (0.05259 + 0.11408 + 0.03630)
when 2022
normaal_kwh * (0.23665 + 0.04452 + 0.03691) + dal_kwh * (0.19408 + 0.04452 + 0.03691)
#year = Date.parse(formatted_hour).year+year_shift
date = Date.parse(formatted_hour).advance(years: year_shift)
case date.to_time.to_i
# Date.parse("2019-12-08").to_time.to_i
# From 8 Dec 2019 until 7 Dec 2020
when 1575759600..1607295600
#normaal_kwh * (0.07865 + 0.11822 + 0.03303) + dal_kwh * (0.06215 + 0.11822 + 0.03303)
normaal_kwh_cost = 0.07865
dal_kwh_cost = 0.06215
# From 8 Dec 2020 until 7 Dec 2021
when 1607382000..1638831600
#normaal_kwh * (0.06782 + 0.11408 + 0.03630) + dal_kwh * (0.05259 + 0.11408 + 0.03630)
normaal_kwh_cost = 0.06782
dal_kwh_cost = 0.05259
# From 8 Dec 2021 until 7 Sept 2022
when 1638918000..1662501600
# normaal_kwh * (0.23665 + 0.04452 + 0.03691) + dal_kwh * (0.19408 + 0.04452 + 0.03691)
normaal_kwh_cost = 0.23665
dal_kwh_cost = 0.19408
# From 8 Sept 2022 until 7 Dec 2022
when 1662588000..1670367600
normaal_kwh_cost = 0.60824
dal_kwh_cost = 0.43701
end
normaal_cost = add_tax(formatted_hour, normaal_kwh,normaal_kwh_cost,0,0) # return_kwh already accounted for
dal_cost = add_tax(formatted_hour, dal_kwh, dal_kwh_cost,0,0)
# result
normaal_cost + dal_cost
end
#
@@ -128,7 +164,7 @@ class Cost
def entsoe_energy_cost(formatted_hour, usage_kwh, return_kwh)
return nil if (usage_kwh.nil? || return_kwh.nil?)
usage_kwh_cost = return_kwh_cost = entsoe.price_at(formatted_hour)
usage_kwh_cost = return_kwh_cost = entsoe.price_at(formatted_hour)*(1+vat_at(Date.parse(formatted_hour)))
add_tax(formatted_hour, usage_kwh, usage_kwh_cost, return_kwh, return_kwh_cost)
end