Latest tarif info added
This commit is contained in:
@@ -1,34 +1,51 @@
|
|||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
EASY_ENERGY_TARIFFS = {}
|
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
|
class Cost
|
||||||
|
|
||||||
attr_accessor :max_charge_kwh
|
attr_accessor :max_charge_kwh
|
||||||
attr_reader :battery, :entsoe
|
attr_reader :battery, :entsoe
|
||||||
|
|
||||||
def initialize(battery_capacity=10.0, max_charge=5.0, storage_cost=0.05)
|
def initialize(zone="Amsterdam", battery_capacity=10.0, max_charge=5.0, storage_cost=0.05)
|
||||||
@entsoe = Entsoe.new(storage_cost)
|
@entsoe = Entsoe.new(zone, storage_cost)
|
||||||
@max_charge_kwh = max_charge
|
@max_charge_kwh = max_charge
|
||||||
@battery = Battery.new(battery_capacity)
|
@battery = Battery.new(battery_capacity)
|
||||||
end
|
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)
|
def format_cost(cost)
|
||||||
cost ? "EUR %0.03f" % cost : "EUR ?"
|
cost ? "EUR %0.03f" % cost : "EUR ?"
|
||||||
end
|
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)
|
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?)
|
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
|
year = Date.parse(formatted_hour).year
|
||||||
case year
|
# calculate tax per kwh - which the sum of energy_tax and ode
|
||||||
when 2020
|
tax = TAX_KWH[year]*vat
|
||||||
usage_kwh * (usage_kwh_cost + 0.11822 + 0.03303) - return_kwh * (return_kwh_cost + 0.11822 + 0.03303)
|
|
||||||
when 2021
|
usage_kwh * (usage_kwh_cost + tax) - return_kwh * (return_kwh_cost + tax)
|
||||||
# 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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
######################################################
|
######################################################
|
||||||
@@ -110,15 +127,34 @@ class Cost
|
|||||||
|
|
||||||
def oxxio_energy_cost(formatted_hour, normaal_kwh, dal_kwh, year_shift=0)
|
def oxxio_energy_cost(formatted_hour, normaal_kwh, dal_kwh, year_shift=0)
|
||||||
return nil if (normaal_kwh.nil? || dal_kwh.nil?)
|
return nil if (normaal_kwh.nil? || dal_kwh.nil?)
|
||||||
year = Date.parse(formatted_hour).year+year_shift
|
#year = Date.parse(formatted_hour).year+year_shift
|
||||||
case year
|
date = Date.parse(formatted_hour).advance(years: year_shift)
|
||||||
when 2020
|
case date.to_time.to_i
|
||||||
normaal_kwh * (0.07865 + 0.11822 + 0.03303) + dal_kwh * (0.06215 + 0.11822 + 0.03303)
|
# Date.parse("2019-12-08").to_time.to_i
|
||||||
when 2021
|
# From 8 Dec 2019 until 7 Dec 2020
|
||||||
normaal_kwh * (0.06782 + 0.11408 + 0.03630) + dal_kwh * (0.05259 + 0.11408 + 0.03630)
|
when 1575759600..1607295600
|
||||||
when 2022
|
#normaal_kwh * (0.07865 + 0.11822 + 0.03303) + dal_kwh * (0.06215 + 0.11822 + 0.03303)
|
||||||
normaal_kwh * (0.23665 + 0.04452 + 0.03691) + dal_kwh * (0.19408 + 0.04452 + 0.03691)
|
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
|
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
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -128,7 +164,7 @@ class Cost
|
|||||||
def entsoe_energy_cost(formatted_hour, usage_kwh, return_kwh)
|
def entsoe_energy_cost(formatted_hour, usage_kwh, return_kwh)
|
||||||
return nil if (usage_kwh.nil? || return_kwh.nil?)
|
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)
|
add_tax(formatted_hour, usage_kwh, usage_kwh_cost, return_kwh, return_kwh_cost)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class Entsoe
|
|||||||
|
|
||||||
def query_day_ahead_prices(date)
|
def query_day_ahead_prices(date)
|
||||||
start_date = date.beginning_of_day
|
start_date = date.beginning_of_day
|
||||||
end_date = date.end_of_day
|
end_date = date.end_of_day.advance(hours: -1)
|
||||||
|
|
||||||
# A44 - Document type => Price Document
|
# A44 - Document type => Price Document
|
||||||
# NL = '10YNL----------L'
|
# NL = '10YNL----------L'
|
||||||
@@ -79,11 +79,12 @@ class Entsoe
|
|||||||
base_request(date, url)
|
base_request(date, url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def hourly_format(prices)
|
def hourly_format(prices)
|
||||||
# in memory hash @kwh_prices is in @zone timezone
|
# in memory hash @kwh_prices is in @zone timezone
|
||||||
prices.to_a.map{|p| [p[0].in_time_zone(@zone).strftime("%F %H"),p[1]]}.to_h
|
prices.to_a.map{|p| [p[0].in_time_zone(zone).strftime("%F %H"),p[1]]}.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
# get position and amount from XML snippet
|
# get position and amount from XML snippet
|
||||||
@@ -92,10 +93,10 @@ class Entsoe
|
|||||||
# <price.amount>196.23</price.amount>
|
# <price.amount>196.23</price.amount>
|
||||||
# </Point>
|
# </Point>
|
||||||
#
|
#
|
||||||
# convert price to EUR per kwh, including VAT (21%)
|
# convert price to EUR per kwh, excluding VAT
|
||||||
#
|
#
|
||||||
def parse_point(xml)
|
def parse_point(xml)
|
||||||
return xml.xpath(".//xmlns:position").text.to_i, ((xml.xpath(".//xmlns:price.amount").text.to_f/1000)*1.21).round(5)
|
return xml.xpath(".//xmlns:position").text.to_i, (xml.xpath(".//xmlns:price.amount").text.to_f/1000).round(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_request(date, url)
|
def base_request(date, url)
|
||||||
|
|||||||
Reference in New Issue
Block a user