marlar

Template til at vise billigste tretimersperiode for dagens elpriser

May 31st, 2022 (edited)
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.85 KB | None | 0 0
  1. {# Fra late_hour og frem tages næste dag med i beregningen af billigste priser #}
  2. {% set late_hour = 20 %}
  3. {% set hour = now().hour %}
  4. {% set day = now().day %}
  5. {% set data = namespace(prices=[]) %}
  6. {% set l=(state_attr('sensor.elpriser_raw', 'records') ) %}
  7. {% set antal = min(l | count, 22 if hour < late_hour and day|int==l[0].HourDK[8:10]|int else 46) %}
  8. {% for i in range(antal) %}
  9.   {% if day | float + (hour>=late_hour) >= l[i].HourDK[8:10] | float %}
  10.     {% if hour>= min(late_hour,22) or hour | float < l[i].HourDK[11:13] | float %}
  11.         {% set avg = ((l[i].TotalPriceDKK | float + l[i+1].TotalPriceDKK | float + l[i+2].TotalPriceDKK | float) / 3) | round(2)  %}
  12.         {% set data.prices = data.prices + [{"hour": i, "avgprice":avg}] %}
  13.     {% endif %}
  14.   {% endif %}
  15. {% endfor %}
  16.  
  17. {% set prices = data.prices | sort(attribute='avgprice') %}
  18.  
  19. Aktuelt er elprisen {{state_attr('sensor.elpriser', 'current_price') | round(2) }} kr pr kWh.
  20.  
  21. Billigste tretimersperiode er mellem kl. {{ l[prices[0].hour].HourDK[11:13]  }} og {{ l[prices[0].hour+2].HourDK[11:13]|int+1 }} med en gns.pris på {{ prices[0].avgprice}} kr/kWh
  22.  
  23. Tid {{ l[prices[0].hour].HourDK[11:16]  }} / Pris {{  l[prices[0].hour].TotalPriceDKK }}
  24. Tid {{ l[prices[0].hour+1].HourDK[11:16]  }} / Pris {{  l[prices[0].hour+1].TotalPriceDKK }}
  25. Tid {{ l[prices[0].hour+2].HourDK[11:16]  }} / Pris {{  l[prices[0].hour+2].TotalPriceDKK }}
  26.  
  27. Næstbilligste periode er mellem kl. {{ l[prices[1].hour].HourDK[11:13]  }} og {{ l[prices[1].hour+2].HourDK[11:13]|int+1 }} med en gns.pris på {{ prices[1].avgprice }} kr/kWh
  28.  
  29. Tid {{ l[prices[1].hour].HourDK[11:16]  }} / Pris {{  l[prices[1].hour].TotalPriceDKK }}
  30. Tid {{ l[prices[1].hour+1].HourDK[11:16]  }} / Pris {{  l[prices[1].hour+1].TotalPriceDKK }}
  31. Tid {{ l[prices[1].hour+2].HourDK[11:16]  }} / Pris {{  l[prices[1].hour+2].TotalPriceDKK }}
  32.  
Add Comment
Please, Sign In to add comment