diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..d8bf14e --- /dev/null +++ b/LICENCE @@ -0,0 +1,9 @@ +Copyright 2024 Adam Štrauch + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/calculator/main.py b/calculator/main.py index e00ac31..840bd2f 100644 --- a/calculator/main.py +++ b/calculator/main.py @@ -22,21 +22,21 @@ def docs(): docs = """ Return spot prices for the whole day with all fees included.

-Options:
-date - date in format YYYY-MM-DD, default is today
-hour - hour of the day, default is current hour, works only when date is today
-monthly_fees - monthly fees, default is 509.24 (D57d, BezDodavatele)
-daily_fees - daily fees, default is 4.18 (BezDodavatele)
-kwh_fees_low - additional fees per kWh in low tariff, usually distribution + other fees, default is 1.62421 (D57d, BezDodavatele)
-kwh_fees_high - additional fees per kWh in high tariff, usually distribution + other fees, default is 1.83474 (D57d, BezDodavatele)
-sell_fees - selling energy fees, default is 0.45 (BezDodavatele)
-num_cheapest_hours - number of cheapest hours to return, default is 8, use this to plan your consumption
-low_tariff_hours - list of low tariff hours, default is 0,1,2,3,4,5,6,7,9,10,11,13,14,16,17,18,20,21,22,23 (D57d, ČEZ)
+**Options:**
+**date** - date in format YYYY-MM-DD, default is today
+**hour** - hour of the day, default is current hour, works only when date is today
+**monthly_fees** - monthly fees, default is 509.24 (D57d, BezDodavatele)
+**daily_fees** - daily fees, default is 4.18 (BezDodavatele)
+**kwh_fees_low** - additional fees per kWh in low tariff, usually distribution + other fees, default is 1.62421 (D57d, BezDodavatele)
+**kwh_fees_high** - additional fees per kWh in high tariff, usually distribution + other fees, default is 1.83474 (D57d, BezDodavatele)
+**sell_fees** - selling energy fees, default is 0.45 (BezDodavatele)
+**num_cheapest_hours** - number of cheapest hours to return, default is 8, use this to plan your consumption
+**low_tariff_hours** - list of low tariff hours, default is 0,1,2,3,4,5,6,7,9,10,11,13,14,16,17,18,20,21,22,23 (D57d, ČEZ)

Output:
-spot - current spot prices on our market
-total - total price for the day including all fees and VAT
-sell - current spot prices minus sell_fees
+**spot** - current spot prices on our market
+**total** - total price for the day including all fees and VAT
+**sell** - current spot prices minus sell_fees

The final price on the invoice is calculated as:
monthly_fees + kWh consumption in low tariff * kwh_fees_low + kWh consumption in high tariff * kwh_fees_high
@@ -47,26 +47,22 @@ Except spot and sell prices all prices include VAT.
Integration into Home Assistant can be done in configuration.yaml file:

``` -sensor: -- platform: rest - resource: "https://pricepower2.rostiapp.cz/price/day" - name: "energy_price" - value_template: "{{ value_json.total.now|round(2) }}" - unit_of_measurement: "CZK/kWh" -- platform: rest - resource: "https://pricepower2.rostiapp.cz/price/day" - name: "energy_market_price" - value_template: "{{ value_json.spot.now|round(2) }}" - unit_of_measurement: "CZK/kWh" -- platform: rest - resource: "https://pricepower2.rostiapp.cz/price/day" - name: "energy_market_price_sell" - value_template: "{{ value_json.sell.now|round(2) }}" - unit_of_measurement: "CZK/kWh" -- platform: rest - resource: "https://pricepower2.rostiapp.cz/price/day" - name: "energy_cheap_hour" - value_template: "{{ value_json.cheapest_hours.is_cheapest }}" +rest: +- resource: https://pricepower2.rostiapp.cz/price/day + scan_interval: 60 + sensor: + - name: "energy_price" + value_template: "{{ value_json.total.now|round(2) }}" + unit_of_measurement: "CZK/kWh" + - name: "energy_market_price" + value_template: "{{ value_json.spot.now|round(2) }}" + unit_of_measurement: "CZK/kWh" + - name: "energy_market_price_sell" + value_template: "{{ value_json.sell.now|round(2) }}" + unit_of_measurement: "CZK/kWh" + binary_sensor: + - name: "energy_cheap_hour" + value_template: "{{ value_json.cheapest_hours.is_cheapest }}" ``` """ @@ -85,6 +81,7 @@ def read_item( no_cache:bool = False, num_cheapest_hours:int = 8, ) -> DayPrice: + is_today = datetime.date.today() == date low_tariff_hours_parsed = [int(x.strip()) for x in low_tariff_hours.split(",")] @@ -96,12 +93,12 @@ def read_item( spot_hours_for_sell = {} spot_hours_total = {} spot_data = get_energy_prices(date, no_cache=no_cache) - for hour, value in spot_data.items(): - kwh_fees = kwh_fees_low if int(hour) in low_tariff_hours_parsed else kwh_fees_high + for key, value in spot_data.items(): + kwh_fees = kwh_fees_low if int(key) in low_tariff_hours_parsed else kwh_fees_high - spot_hours[hour] = value / currency_ratio - spot_hours_total[hour] = (value / currency_ratio + kwh_fees) * VAT - spot_hours_for_sell[hour] = value / currency_ratio - sell_fees + spot_hours[key] = value / currency_ratio + spot_hours_total[key] = (value / currency_ratio + kwh_fees) * VAT + spot_hours_for_sell[key] = value / currency_ratio - sell_fees spot = Price(hours=spot_hours, now=spot_hours[str(hour)] if is_today else None) @@ -118,6 +115,7 @@ def read_item( kwh_fees_high=kwh_fees_high * VAT, sell_fees=sell_fees, low_tariff_hours=low_tariff_hours_parsed, + hour=hour, vat=VAT, spot=spot, total=spot_total, diff --git a/calculator/schema.py b/calculator/schema.py index 3703bc2..13b9807 100644 --- a/calculator/schema.py +++ b/calculator/schema.py @@ -22,6 +22,7 @@ class DayPrice: kwh_fees_high: float sell_fees: float low_tariff_hours: List[int] + hour: int vat: float spot: Price total: Price