File: energy.py

package info (click to toggle)
python-easyenergy 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 852 kB
  • sloc: python: 772; makefile: 5
file content (65 lines) | stat: -rw-r--r-- 3,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Asynchronous Python client for the easyEnergy API."""

import asyncio
from datetime import date, timedelta

import pytz

from easyenergy import EasyEnergy, VatOption


async def main() -> None:
    """Show example on fetching the energy prices from easyEnergy."""
    async with EasyEnergy(vat=VatOption.INCLUDE) as client:
        local = pytz.timezone("Europe/Amsterdam")
        today = date(2024, 1, 30)
        tomorrow = date(2024, 1, 31)

        # Select your test readings
        switch_e_today: bool = True
        switch_e_tomorrow: bool = True

        if switch_e_today:
            energy_today = await client.energy_prices(start_date=today, end_date=today)
            utc_next_hour = energy_today.utcnow() + timedelta(hours=1)

            print("--- ENERGY TODAY ---")
            print(f"Extremas usage price: {energy_today.extreme_usage_prices}")
            print(f"Extremas return price: {energy_today.extreme_return_prices}")
            print(f"Average usage price: {energy_today.average_usage_price}")
            print(f"Average return price: {energy_today.average_return_price}")
            print(f"Percentage max - Usage: {energy_today.pct_of_max_usage}%")
            print(f"Percentage max - Return: {energy_today.pct_of_max_return}%")
            print()

            highest_time_usage = energy_today.highest_usage_price_time.astimezone(local)
            print(f"Highest price time - Usage: {highest_time_usage}")
            lowest_time_usage = energy_today.lowest_usage_price_time.astimezone(local)
            print(f"Lowest price time - Usage: {lowest_time_usage}")
            print()
            print(f"Current usage price: {energy_today.current_usage_price}")
            print(f"Current return price: {energy_today.current_return_price}")
            print(f"Next hourprice: {energy_today.price_at_time(utc_next_hour)}")

            lower_hours: int = energy_today.hours_priced_equal_or_lower_usage
            highest_hours: int = energy_today.hours_priced_equal_or_higher_return
            print(f"Lower hours (usage): {lower_hours}")
            print(f"Higher hours (return): {highest_hours}")

        if switch_e_tomorrow:
            energy_tomorrow = await client.energy_prices(tomorrow, tomorrow)
            print()
            print("--- ENERGY TOMORROW ---")
            print(f"Extremas usage price: {energy_tomorrow.extreme_usage_prices}")
            print(f"Extremas return price: {energy_tomorrow.extreme_return_prices}")
            print(f"Average usage price: {energy_tomorrow.average_usage_price}")
            print(f"Average return price: {energy_tomorrow.average_return_price}")
            print()
            highest_time = energy_tomorrow.highest_usage_price_time.astimezone(local)
            print(f"Highest price time - Usage: {highest_time}")
            lowest_time = energy_tomorrow.lowest_usage_price_time.astimezone(local)
            print(f"Lowest price time - Usage: {lowest_time}")


if __name__ == "__main__":
    asyncio.run(main())