Guest User

Untitled

a guest
Oct 16th, 2025
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. template:
  2. - triggers:
  3. - trigger: time_pattern
  4. minutes: /1
  5. - trigger: homeassistant
  6. event: start
  7. actions:
  8. - action: nordpool.get_prices_for_date
  9. data:
  10. config_entry: 01K4QBH1H606SDS1V28KGR32K7
  11. date: "{{ now().date() - timedelta(days=1) }}"
  12. areas: FI
  13. currency: EUR
  14. response_variable: yesterday_price
  15. - action: nordpool.get_prices_for_date
  16. data:
  17. config_entry: 01K4QBH1H606SDS1V28KGR32K7
  18. date: "{{ now().date() }}"
  19. areas: FI
  20. currency: EUR
  21. response_variable: today_price
  22. - action: nordpool.get_prices_for_date
  23. data:
  24. config_entry: 01K4QBH1H606SDS1V28KGR32K7
  25. date: "{{ now().date() + timedelta(days=1) }}"
  26. areas: FI
  27. currency: EUR
  28. response_variable: tomorrow_price
  29. sensor:
  30. - name: Electricity prices Dev
  31. unique_id: electricity_prices_dev
  32. unit_of_measurement: "snt/kWh"
  33. icon: mdi:cash
  34. state: >
  35. {%- set region = (this.attributes.get('region', 'FI') | string) -%}
  36. {%- set tax = (this.attributes.get('tax', 1.0) | float) -%}
  37. {%- set additional_cost = (this.attributes.get('additional_cost', 0.0) | float) -%}
  38. {% if (today_price is mapping) and (tomorrow_price is mapping) %}
  39. {% set data = namespace(prices=[]) %}
  40. {% for state in yesterday_price[region][-4:] %}
  41. {% set data.prices = data.prices + [(((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)] %}
  42. {% endfor %}
  43. {% for state in today_price[region] %}
  44. {% set data.prices = data.prices + [(((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)] %}
  45. {% endfor %}
  46. {% for state in tomorrow_price[region] %}
  47. {% set data.prices = data.prices + [(((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)] %}
  48. {% endfor %}
  49. {{min(data.prices)}}
  50. {% else %}
  51. unavailable
  52. {% endif %}
  53. attributes:
  54. tomorrow_valid: >
  55. {%- set region = (this.attributes.get('region', 'FI') | string) -%}
  56. {%- if (tomorrow_price is mapping) %}
  57. {%- if tomorrow_price[region] | list | count > 0 -%}
  58. {{ true | bool }}
  59. {%- else %}
  60. {{ false | bool }}
  61. {%- endif %}
  62. {%- else %}
  63. {{ false | bool }}
  64. {%- endif %}
  65. data: >
  66. {%- set region = (this.attributes.get('region', 'FI') | string) -%}
  67. {%- set tax = (this.attributes.get('tax', 1.0) | float) -%}
  68. {%- set additional_cost = (this.attributes.get('additional_cost', 0.0) | float) -%}
  69.  
  70. {% if (yesterday_price is mapping) and (today_price is mapping) and (tomorrow_price is mapping) %}
  71. {% set data = namespace(prices=[]) %}
  72. {% for state in yesterday_price[region][-4:] %}
  73. {% set local_start = as_datetime(state.start).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  74. {% set local_end = as_datetime(state.end).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  75. {% set data.prices = data.prices + [{'start':local_start, 'end':local_end, 'price': (((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)}] %}
  76. {% endfor %}
  77. {% for state in today_price[region] %}
  78. {% set local_start = as_datetime(state.start).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  79. {% set local_end = as_datetime(state.end).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  80. {% set data.prices = data.prices + [{'start':local_start, 'end':local_end, 'price': (((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)}] %}
  81. {% endfor %}
  82. {% for state in tomorrow_price[region] %}
  83. {% set local_start = as_datetime(state.start).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  84. {% set local_end = as_datetime(state.end).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
  85. {% set data.prices = data.prices + [{'start':local_start, 'end':local_end, 'price': (((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)}] %}
  86. {% endfor %}
  87. {{data.prices}}
  88. {% else %}
  89. []
  90. {% endif %}
  91. tax: 1.255
  92. additional_cost: 0
  93. region: FI
  94.  
Advertisement
Add Comment
Please, Sign In to add comment