-
-
Notifications
You must be signed in to change notification settings - Fork 28
EnergyZero
Jonas Karlsson edited this page Jul 20, 2024
·
4 revisions
To use the EnergyZero integration, the following template sensor can be used to create the price input.
Please report issues here.
Replace the value for config_entry
with your config entry, see EnergyZero.
Replace the value for unique_id
with your unique_id. Either any previously unused id, e.g. energy_zero_template_price_sensor
, or use any online UUID generator.
template:
- trigger:
- platform: time_pattern
hours: "/1"
- platform: homeassistant
event: start
action:
- service: energyzero.get_energy_prices
data:
incl_vat: false
config_entry: ec3a34e8bc69248bd067e2211b0d67ab_replace_with_your_config_entry
start: "{{ today_at() }}"
end: "{{ today_at() + timedelta(days=2) }}"
response_variable: prices
sensor:
- name: Energy Zero template prices
unit_of_measurement: "€/kWh"
unique_id: ff1849c3-b5c5-498a-873e-fb70b37ec7b9_replace_with_your_unique_id
# availability: "{{ prices.prices | has_value }}"
state: "{{ prices.prices | selectattr('timestamp', '<=', utcnow().strftime('%Y-%m-%d %H:%M:%S+00:00')) | map(attribute='price') | list | last }}"
attributes:
prices_today: >
{%- set forecast = prices.prices %}
{%- set time_key = 'timestamp' %}
{%- set price_key = 'price' %}
{%- set ns = namespace(data=[]) %}
{%- for i in forecast | default([], true) if as_local(as_datetime(i[time_key])).date() == now().date() %}
{%- set ns.data = ns.data + [dict(time= as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key] )] %}
{%- endfor %}
{{ ns.data }}
prices_tomorrow: >
{%- set forecast = prices.prices %}
{%- set time_key = 'timestamp' %}
{%- set price_key = 'price' %}
{%- set ns = namespace(data=[]) %}
{%- for i in forecast | default([], true) if as_local(as_datetime(i[time_key])).date() == (now()+timedelta(days=1)).date() %}
{%- set ns.data = ns.data + [dict(time= as_local(as_datetime(i[time_key])).isoformat(), price = i[price_key] )] %}
{%- endfor %}
{{ ns.data }}