Compare commits

..

10 Commits

Author SHA1 Message Date
9470623915 Fix Oxxio rates 2026 2026-01-03 21:07:29 +01:00
=
72cd644528 Fix: Interpolate missing ENTSOE price data points
Handle missing hourly price data from ENTSOE API by interpolating
values from adjacent time slots instead of returning nil.
2026-01-03 20:42:22 +01:00
85eaceaad2 New blurp for new meter 2026-01-03 20:11:49 +01:00
b40f4d2dc6 Add 2026 tarifs and rates 2026-01-03 19:58:03 +01:00
Aart van Halteren
24dd351249 Convert gas timestamp to datetime object 2025-07-17 13:11:28 +02:00
Aart van Halteren
63b2260ba0 refactor 2025-07-17 12:49:46 +02:00
Aart van Halteren
211b6e7cac debug info 2025-07-17 12:46:16 +02:00
Aart van Halteren
968a5cea2f two stage matching 2025-07-17 12:42:13 +02:00
Aart van Halteren
c165f24632 extra test 2025-07-17 12:37:41 +02:00
Aart van Halteren
b303331581 bug fix 2025-07-17 12:32:28 +02:00
5 changed files with 250 additions and 134 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
.config
.project
*.pid
data

View File

@@ -47,7 +47,6 @@ class InSyncState < StatePattern::State
end
def handle_frame(frame_lines)
gas_pattern = /^([0-1:24\.2\.1]+)\((\d{12}[SW])\)\((\d{5}\.\d{3})\*m3\)$/
# prepare DB record
last_reading = Reading.last
@@ -79,9 +78,12 @@ class InSyncState < StatePattern::State
end
if line.match(/0-0:96.14.0/) # Hoog/laag tarief
reading.high_tarif = line.split(/0-0:96.14.0\(|\)/).join.eql?("0002")
end
if match = line.match(/0-1:24.3.0/) # Gas verbruik (1x per uur een nieuwe stand)
p "Gas reading: #{match[1]} (#{match[2]})"
end
# example line: "0-1:24.2.1(250717121000S)(00000.474*m3)"
if match = line.match(/^(0-1:24.2.1)\(([^)]+)\)\(([\d.]+)\*m3\)$/) # Gas verbruik (1x per uur een nieuwe stand)
#p "Gas reading: #{match[1]} (#{match[2]})"
#datetime = DateTime.strptime(match[2][0..11], "%y%m%d%H%M%S")
#p "Gas reading at #{datetime}."
reading.total_m3_gas_consumed = match[3].to_f
end
}

View File

@@ -6,8 +6,8 @@ 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, 2023 => 0.12599, 2024 => 0.10880, 2025 => 0.10154}
ODE_KWH = { 2020 => 0.0273, 2021 => 0.0300, 2022 => 0.0305, 2023 => 0.0, 2024 => 0.0, 2025 => 0.0}
ENERGY_TAX_KWH = { 2020 => 0.09770, 2021 => 0.09428, 2022 => 0.03679, 2023 => 0.12599, 2024 => 0.10880, 2025 => 0.10154, 2026 => 0.09157 }
ODE_KWH = { 2020 => 0.0273, 2021 => 0.0300, 2022 => 0.0305, 2023 => 0.0, 2024 => 0.0, 2025 => 0.0, 2026 =>0.0}
# merge by adding values
TAX_KWH = ENERGY_TAX_KWH.merge(ODE_KWH){|key, energy_tax, ode| energy_tax + ode}
@@ -82,10 +82,7 @@ class Cost
end
when 2023
0.018
when 2024
# opslag met BTW: 0,02178
0.018457
when 2025
when 2024..2026
# opslag met BTW: 0,02178
0.018457
end
@@ -93,7 +90,8 @@ class Cost
def easy_energy_cost(formatted_hour, usage_kwh, return_kwh)
return nil if (usage_kwh.nil? || return_kwh.nil?)
#p "easy_energy_cost for " + formatted_hour
usage_kwh_cost = return_kwh_cost = (entsoe.price_at(formatted_hour)+easy_energy_rate(formatted_hour))*(1+vat_at(Date.parse(formatted_hour)))
add_tax(formatted_hour, usage_kwh, usage_kwh_cost, return_kwh, return_kwh_cost)
end
@@ -260,6 +258,8 @@ class Cost
0.25767769
when 2025
high_tariff ? 0.2695 : 0.2296
when 2026
high_tariff ? 0.23186 : 0.22442
end
end
@@ -303,6 +303,9 @@ class Cost
vat = 1 + vat_at(Date.parse(formatted_hour))
normaal_kwh_cost = 0.2695*vat
dal_kwh_cost = 0.2296*vat
when 1767225600..1785887999 # 2026 full year
normaal_kwh_cost = 0.19161
dal_kwh_cost = 0.18547
else
p "Not supported interval Oxxio for value: %d" % date.to_time.to_i
# catch-all, incase 'formated_hour' is outside any of the cases

View File

@@ -103,15 +103,61 @@ class Entsoe
formatted_date = date.strftime("%F")
doc = Nokogiri::XML(URI.open(url))
#p "Entsoe prices: %s" % doc
prices = doc.xpath('.//xmlns:Point').map{|p| parse_point(p)}
begin
# get start_time (in UTC) from XML docment
start_time = DateTime.parse(doc.xpath('.//xmlns:period.timeInterval//xmlns:start').text)
# Get resolution to determine expected number of positions
resolution = doc.xpath('.//xmlns:resolution').text
interval_minutes = resolution == 'PT15M' ? 15 : 60
expected_positions = (24 * 60) / interval_minutes
# Create hash from available prices
price_hash = prices.to_h
# Fill in missing positions by interpolating from adjacent values
complete_prices = {}
(1..expected_positions).each do |position|
if price_hash.key?(position)
complete_prices[position] = price_hash[position]
else
# Find previous and next available prices for interpolation
prev_price = (position-1).downto(1).find { |p| price_hash.key?(p) }
next_price = (position+1).upto(expected_positions).find { |p| price_hash.key?(p) }
if prev_price && next_price
# Interpolate between previous and next
complete_prices[position] = ((price_hash[prev_price] + price_hash[next_price]) / 2.0).round(5)
elsif prev_price
# Use previous price as fallback
complete_prices[position] = price_hash[prev_price]
elsif next_price
# Use next price as fallback
complete_prices[position] = price_hash[next_price]
end
# Calculate the formatted hour for the warning message
hour_offset = interval_minutes == 15 ? (position - 1) / 4 : (position - 1)
missing_hour = start_time.advance(hours: hour_offset).in_time_zone(zone).strftime("%F %H")
p "Warning: Missing Entsoe data for #{missing_hour}, interpolated value: #{complete_prices[position]}"
end
end
#returns a hash with keys formatted "yyyy-mm-dd hr" and values price (per kwh)
# <position> tag runs from 1-24. We need hours from 00-23, therefore substracting 1
prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h
# <position> tag runs from 1-96 for 15min intervals. Convert to hourly by taking first interval of each hour
if interval_minutes == 15
# For 15-minute intervals, use the first interval of each hour (positions 1, 5, 9, 13, ...)
complete_prices.select { |pos, _| (pos - 1) % 4 == 0 }
.map { |pos, price| [start_time.advance(hours: ((pos - 1) / 4)), price] }
.to_h
else
# For hourly data (position runs from 1-24, we need hours from 00-23)
complete_prices.map { |pos, price| [start_time.advance(hours: (pos - 1)), price] }.to_h
end
rescue Date::Error => e
p e.message
{}

View File

@@ -1,121 +1,185 @@
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.035*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.28*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(1)
!
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.036*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.31*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(1)
!
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.037*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.32*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(1)
!
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.038*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.32*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(1)
!
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.039*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.32*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(1)
!
/ISk5\2ME382-1003
0-0:96.1.1(4B413650303035313238303430383132)
1-0:1.8.1(00553.931*kWh)
1-0:1.8.2(00431.594*kWh)
1-0:2.8.1(00093.034*kWh)
1-0:2.8.2(00147.040*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0000.00*kW)
1-0:2.7.0(0000.30*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
0-0:96.13.1()
0-0:96.13.0()
0-1:24.1.0(3)
0-1:96.1.0(3238303131303031323439333134383132)
0-1:24.3.0(130626090000)(00)(60)(1)(0-1:24.2.1)(m3)
(00309.466)
0-1:24.4.0(3)
!
3233)
1-0:1.8.1(001402.671*kWh)
1-0:1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.283*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.283*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!7603
/CTA5ZIV-METER
1-3:2.671*kWh)
1-0:1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.286*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.286*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!B5E2
/CTA5ZIV-METER
1-3:0.2.8(50)
0-0::1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.335*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.335*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!6D5D
/CTA5ZIV-METER
1-3:0.2.8(50)
0-0:1.0.0(260103201104W)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.276*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.276*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!FDB1
3233)
1-0:1.8.1(001402.673*kWh)
1-0:1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.344*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(006*A)
1-0:21.7.0(01.344*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!E9B8
/CTA5ZIV-METER
1-3:0.2.3*kWh)
1-0:1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.319*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.319*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!F0CD
/CTA5ZIV-METER
1-3:0.2.8(50)
0-0:1.0.0(2001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.336*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.336*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!CCE2
/CTA5ZIV-METER
1-3:0.2.8(50)
0-0:1.0.0(260103201108W)
0-0:96.1.1(4530303839303031303230373731393233)
1-0:1.8.1(001402.674*kWh)
1-0:1.8.2(001130.208*kWh)
1-0:2.8.1(000080.565*kWh)
1-0:2.8.2(000205.556*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(01.319*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00015)
0-0:96.7.9(00004)
1-0:99.97.0(0)(0-0:96.7.19)
1-0:32.32.0(00000)
1-0:32.36.0(00003)
0-0:96.13.0()
1-0:32.7.0(236.0*V)
1-0:31.7.0(005*A)
1-0:21.7.0(01.319*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0-1:96.1.0(4730303933303034333734333338333235)
0-1:24.2.1(260103201000W)(00272.130*m3)
!B4B3