Guest User

Untitled

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