diff --git a/src/clj/pmagnus/elprice/web/controllers/tariffs.clj b/src/clj/pmagnus/elprice/web/controllers/tariffs.clj new file mode 100644 index 0000000..901f94f --- /dev/null +++ b/src/clj/pmagnus/elprice/web/controllers/tariffs.clj @@ -0,0 +1,38 @@ +(ns pmagnus.elprice.web.controllers.tariffs + (:import + [java.time LocalDateTime])) + +(def n1-tariffs + "N1 network tariffs in øre/kWh (incl. VAT), effective 2026-01-01. + Source: https://n1.dk/elnetkunder/gaeldende-priser" + {:summer {:low 10.98 ;; 00:00-06:00 + :high 16.47 ;; 06:00-17:00, 21:00-24:00 + :peak 42.83} ;; 17:00-21:00 + :winter {:low 10.98 + :high 32.95 + :peak 98.84}}) + +(defn season + "Returns :summer (Apr-Sep) or :winter (Oct-Mar) for a given month (1-12)." + [month] + (if (<= 4 month 9) :summer :winter)) + +(defn load-level + "Returns :low, :high, or :peak for a given hour (0-23). + Low: 00:00-06:00 + High: 06:00-17:00, 21:00-24:00 + Peak: 17:00-21:00" + [hour] + (cond + (< hour 6) :low + (and (<= 6 hour) (< hour 17)) :high + (and (<= 17 hour) (< hour 21)) :peak + :else :high)) + +(defn tariff-for-hour + "Returns the applicable N1 tariff in øre/kWh. + Can be called with (month, hour) or a LocalDateTime." + ([^LocalDateTime dt] + (tariff-for-hour (.getMonthValue dt) (.getHour dt))) + ([month hour] + (get-in n1-tariffs [(season month) (load-level hour)])))