Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - triggers:
- - trigger: time_pattern
- minutes: /1
- - trigger: homeassistant
- event: start
- actions:
- - action: nordpool.get_prices_for_date
- data:
- config_entry: 01K6XA6J47AEST7871J3TQ4QNE
- date: "{{ now().date() }}"
- areas: SE3
- currency: SEK
- response_variable: today_price
- - action: nordpool.get_prices_for_date
- data:
- config_entry: 01K6XA6J47AEST7871J3TQ4QNE
- date: "{{ now().date() + timedelta(days=1) }}"
- areas: SE3
- currency: SEK
- response_variable: tomorrow_price
- sensor:
- - name: Electricity prices
- unique_id: electricity_prices
- unit_of_measurement: "öre/kWh"
- icon: mdi:cash
- state: >
- {%- set region = (this.attributes.get('region', 'SE3') | string) -%}
- {%- set tax = (this.attributes.get('tax', 1.0) | float) -%}
- {%- set additional_cost = (this.attributes.get('additional_cost', 0.0) | float) -%}
- {% if (today_price is mapping) and (tomorrow_price is mapping) %}
- {% set data = namespace(prices=[]) %}
- {% for state in today_price[region] %}
- {% set data.prices = data.prices + [(((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)] %}
- {% endfor %}
- {% for state in tomorrow_price[region] %}
- {% set data.prices = data.prices + [(((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)] %}
- {% endfor %}
- {{min(data.prices)}}
- {% else %}
- unavailable
- {% endif %}
- attributes:
- tomorrow_valid: >
- {%- set region = (this.attributes.get('region', 'SE3') | string) -%}
- {%- if (tomorrow_price is mapping) %}
- {%- if tomorrow_price[region] | list | count > 0 -%}
- {{ true | bool }}
- {%- else %}
- {{ false | bool }}
- {%- endif %}
- {%- else %}
- {{ false | bool }}
- {%- endif %}
- data: >
- {%- set region = (this.attributes.get('region', 'SE3') | string) -%}
- {%- set tax = (this.attributes.get('tax', 1.0) | float) -%}
- {%- set additional_cost = (this.attributes.get('additional_cost', 0.0) | float) -%}
- {% if (today_price is mapping) and (tomorrow_price is mapping) %}
- {% set data = namespace(prices=[]) %}
- {% for state in today_price[region] %}
- {% set local_start = as_datetime(state.start).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
- {% set local_end = as_datetime(state.end).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
- {% set data.prices = data.prices + [{'start':local_start, 'end':local_end, 'price': (((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)}] %}
- {% endfor %}
- {% for state in tomorrow_price[region] %}
- {% set local_start = as_datetime(state.start).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
- {% set local_end = as_datetime(state.end).astimezone().strftime('%Y-%m-%d %H:%M:%S') %}
- {% set data.prices = data.prices + [{'start':local_start, 'end':local_end, 'price': (((state.price/10 | float) * tax + additional_cost)) | round(3, default=0)}] %}
- {% endfor %}
- {{data.prices}}
- {% else %}
- []
- {% endif %}
- tax: 1.25
- additional_cost: 0
- region: SE3
Advertisement
Add Comment
Please, Sign In to add comment