Advertisement
seston

elektrihinna arvutus

Oct 18th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. template:
  2. - sensor:
  3. - name: "Elektrihinna Arvutus"
  4. state: >
  5. {% set peak_price_weekday = 0.0818 %}
  6. {% set peak_price_weekend = 0.0474 %}
  7. {% set day_price = 0.0529 %}
  8. {% set night_price = 0.0303 %}
  9. {% set monthly_fee = 19.84 %}
  10.  
  11. {% set current_time = now() %}
  12. {% set current_hour = current_time.hour %}
  13. {% set current_day = current_time.strftime('%A') %}
  14.  
  15. {% set total_cost = monthly_fee %}
  16.  
  17. {% if current_day in ['Saturday', 'Sunday'] %}
  18. {% if current_hour >= 16 and current_hour < 20 %}
  19. {% set total_cost = total_cost + peak_price_weekend %}
  20. {% elif current_hour >= 7 and current_hour < 22 %}
  21. {% set total_cost = total_cost + day_price %}
  22. {% else %}
  23. {% set total_cost = total_cost + night_price %}
  24. {% endif %}
  25. {% else %}
  26. {% if (current_hour >= 9 and current_hour < 12) or (current_hour >= 16 and current_hour < 20) %}
  27. {% set total_cost = total_cost + peak_price_weekday %}
  28. {% elif current_hour >= 7 and current_hour < 22 %}
  29. {% set total_cost = total_cost + day_price %}
  30. {% else %}
  31. {% set total_cost = total_cost + night_price %}
  32. {% endif %}
  33. {% endif %}
  34.  
  35. {{ total_cost | round(2) }}
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement