Hoppa till huvudinnehåll

Använd timpriser i Home Assistant

Den här guiden visar hur du får in elnätsavgiften per timme i Home Assistant och använder den för att köra en elbilsladdare, värmepump eller annan apparat under dygnets billigaste timmar. Inga tillägg behövs, bara Home Assistants inbyggda integrationer RESTful och Template.

Det här får du​

EntitetVad den visar
sensor.grid_fee_pricesHämtar priserna en gång i timmen. Priserna sparas i attributet actual.
sensor.grid_fee_price_nowPriset för aktuell timme, i SEK/kW inkl. moms. Använd den i dashboards och historikgrafer.
binary_sensor.grid_fee_cheap_houron under dygnets 4 billigaste timmar. Använd den för att starta och stoppa apparater.

Dessutom en exempelautomation som slår på och av en elbilsladdare.

Konfiguration​

Lägg till det här i din configuration.yaml, ändra produkten och switch.ev_charger så att de passar din installation, kontrollera sedan konfigurationen och starta om Home Assistant:

configuration.yaml
# Göteborg Energi hourly grid fee in Home Assistant.
# Add to configuration.yaml, check the configuration and restart Home Assistant.

rest:
- resource: https://api.uat.goteborgenergi.cloud/gridtariff/v0/prices?product=GN6KWST
scan_interval: 3600 # fetch once an hour
timeout: 30
sensor:
- name: Grid fee prices
unique_id: goteborg_energi_grid_fee_prices
# The state is the number of hours with set prices.
# The prices themselves are stored in the "actual" attribute.
value_template: "{{ value_json.actual | count }}"
json_attributes:
- actual

template:
- sensor:
- name: Grid fee price now
unique_id: goteborg_energi_grid_fee_price_now
unit_of_measurement: "SEK/kW"
availability: "{{ state_attr('sensor.grid_fee_prices', 'actual') is not none }}"
state: >
{% set ns = namespace(price=none) %}
{% for hour in state_attr('sensor.grid_fee_prices', 'actual') or [] %}
{% if as_timestamp(hour.start) <= now().timestamp() < as_timestamp(hour.end) %}
{% set ns.price = hour.priceIncVat %}
{% endif %}
{% endfor %}
{{ ns.price }}

- binary_sensor:
# On during the cheapest hours of the day
- name: Grid fee cheap hour
unique_id: goteborg_energi_grid_fee_cheap_hour
availability: "{{ state_attr('sensor.grid_fee_prices', 'actual') is not none }}"
state: >
{% set hours_needed = 4 %}
{% set today = now().date() | string %}
{% set ns = namespace(prices=[], now_price=none) %}
{% for hour in state_attr('sensor.grid_fee_prices', 'actual') or [] %}
{% if hour.start[:10] == today %}
{% set ns.prices = ns.prices + [hour.priceIncVat] %}
{% endif %}
{% if as_timestamp(hour.start) <= now().timestamp() < as_timestamp(hour.end) %}
{% set ns.now_price = hour.priceIncVat %}
{% endif %}
{% endfor %}
{% if ns.now_price is none or not ns.prices %}
false
{% else %}
{% set limit = (ns.prices | sort)[[hours_needed, ns.prices | count] | min - 1] %}
{{ ns.now_price <= limit }}
{% endif %}

automation:
- alias: Charge the EV during cheap grid fee hours
triggers:
- trigger: state
entity_id: binary_sensor.grid_fee_cheap_hour
to: "on"
id: cheap
- trigger: state
entity_id: binary_sensor.grid_fee_cheap_hour
from: "on"
id: not_cheap
actions:
- choose:
- conditions:
- condition: trigger
id: cheap
sequence:
- action: switch.turn_on
target:
entity_id: switch.ev_charger # replace with your charger
default:
- action: switch.turn_off
target:
entity_id: switch.ev_charger

Om du redan har avsnitten rest:, template: eller automation: lägger du till posterna i dem i stället för att skapa nya. Du kan också skapa automationen i Home Assistants gränssnitt i stället.

Anpassa​

  • Antal timmar: ändra hours_needed i binärsensorn. Om flera timmar har samma pris kan fler timmar än så markeras som billiga.
  • Din tariff: byt ut GN6KWST i URL:en mot produkten för din tariff. Bara tariffer med effektavgift per timme har timpriser.
  • När priserna uppdateras: nästa dygns priser fastställs senast 15:00. Hämtning en gång i timmen fångar upp dem i tid.
anteckning

Binärsensorn väljer de billigaste timmarna bland dagens timmar. Om du vill planera över midnatt, till exempel för att ladda bilen över natten, jämför du i stället timmarna från nu fram till den tidpunkt då den ska vara klar.