ITex Services s.r.o.

[ ITexSpot · Home Assistant ]

Electricity spot price in Home Assistant

One configuration file: the current price, a “cheap now” binary sensor, the cheapest window and a weekly outlook for an ApexCharts graph.

Beta · free · read-only key

Czech bidding zone (CZ) only — prices in CZK, Czech distribution tariffs.

1. Addresses with the key in secrets.yaml

secrets.yaml
itexspot_ted: "https://api.itexservices.cz/v1/k/its_YOURKEY/ted.json"
itexspot_vyhled: "https://api.itexservices.cz/v1/k/its_YOURKEY/vyhled.json?hodin=168"

The key is in the path of the address: the response then goes through our cache and is faster. Thanks to secrets.yaml, the address does not appear in a configuration you might share. A key in the header (headers: Authorization: Bearer …) works too, but such a response is not stored in the cache and every request goes all the way to the computation — treat it only as an alternative.

2. Configuration package

Enable packages (homeassistant: packages: !include_dir_named packages in configuration.yaml), save this file as packages/itexspot.yaml and restart Home Assistant.

packages/itexspot.yaml
# packages/itexspot.yaml — ITexSpot API (beta)
# Addresses with the key belong in secrets.yaml (see step 1).

rest:
  - resource: !secret itexspot_ted
    scan_interval: 1200         # 20 min — data changes 3× a day
    timeout: 20
    sensor:
      - name: "ITexSpot price now"
        unique_id: itexspot_cena_ted
        value_template: "{{ value_json.cena_ted }}"
        unit_of_measurement: "CZK/kWh"
        device_class: monetary
        state_class: measurement
        json_attributes:
          - stav
          - uroven_ted
          - levno_ted
          - zmena_urovne_v
          - okno_3h
          - nejdrazsi_3h
          - p_zaporna_dnes
          - pockat
          - poradi_ted
          - v_n_nejlevnejsich
          - nejlevnejsi_hodina
          - stari_min
          - dalsi_aktualizace
      - name: "ITexSpot cheap window start"
        unique_id: itexspot_okno_od
        value_template: "{{ value_json.okno_3h.od if value_json.okno_3h else none }}"
        device_class: timestamp

  - resource: !secret itexspot_vyhled
    scan_interval: 14400        # 4 h — the outlook changes 3× a day
    timeout: 20
    sensor:
      - name: "ITexSpot outlook"
        unique_id: itexspot_vyhled
        value_template: "{{ value_json.vydano }}"
        json_attributes:
          - sloty

template:
  - binary_sensor:
      - name: "ITexSpot cheap now"
        unique_id: itexspot_levno_ted
        state: "{{ state_attr('sensor.itexspot_cena_ted', 'levno_ted') == true }}"
        availability: "{{ has_value('sensor.itexspot_cena_ted') }}"

recorder:
  exclude:
    entities:
      - sensor.itexspot_vyhled   # large attribute, does not belong in history

This creates the entities sensor.itexspot_cena_ted (with attributes for the window, “wait” and data age), sensor.itexspot_okno_od, binary_sensor.itexspot_levno_ted and sensor.itexspot_vyhled with the outlook in the sloty attribute. The entity ids and attribute names come from the API contract and stay in Czech. The price is the final price if the key has a stored tariff, otherwise the plain spot price.

The package makes about 78 requests a day (current price every 20 min, outlook every 4 h), so it fits comfortably within the Free tier limit (300 requests a day). More frequent requests bring nothing, the data changes three times a day; the “cheap now” level changes on the full hour, so it may arrive up to 20 minutes late.

3. Weekly graph (ApexCharts)

With the apexcharts-card add-on from HACS you can draw the outlook including the uncertainty band:

Lovelace card
type: custom:apexcharts-card
header:
  show: true
  title: Electricity price — 7 days
graph_span: 7d
span:
  start: day
series:
  - entity: sensor.itexspot_vyhled
    name: Price
    type: line
    curve: stepline
    data_generator: |
      return entity.attributes.sloty.map(s => [new Date(s.od).getTime(), s.koncova ?? s.spot]);
  - entity: sensor.itexspot_vyhled
    name: Band low
    type: line
    opacity: 0.3
    data_generator: |
      return entity.attributes.sloty.map(s => [new Date(s.od).getTime(), s.p10 ?? s.spot]);
  - entity: sensor.itexspot_vyhled
    name: Band high
    type: line
    opacity: 0.3
    data_generator: |
      return entity.attributes.sloty.map(s => [new Date(s.od).getTime(), s.p90 ?? s.spot]);

4. Example automation

boiler by cheap hours
automation:
  - alias: "Boiler in cheap hours"
    triggers:
      - trigger: state
        entity_id: binary_sensor.itexspot_levno_ted
    actions:
      - action: >-
          {{ 'switch.turn_on' if is_state('binary_sensor.itexspot_levno_ted', 'on') else 'switch.turn_off' }}
        target:
          entity_id: switch.boiler

This automation is the simplest possible. For real-world use, use the version with a safeguard below — during an API outage it switches the boiler to a fallback window.

5. Battery plan (optional)

Add the recommended battery plan (baterie.json) with another REST sensor, e.g. every 1 h with the address https://api.itexservices.cz/v1/k/its_YOURKEY/baterie.json?kapacita=10&vykon=5&soc=50. The state of charge in the address is fixed; for the current value use resource_template. The plan is only a recommendation — you decide how your battery is controlled.

Safe behavior during an API outage

The API may stop responding for a while, return an error or return stale data. Your home automation has to expect this — build it so that an outage breaks nothing:

  • The relay stays in its last safe state. Without valid data, do not switch anything on because of a “cheap hour”. Return devices to the behavior the house would have without ITexSpot (boiler on a time schedule, inverter without export limiting, battery in normal mode).
  • Fallback window. For loads that must run (boiler, charging), keep a fixed window in usually cheap hours, for example 1–5 am. When the data is not valid, run by that window.
  • Detect invalid data. Always check the data status. In JSON it is stav (ok, stara_data = stale data, limit, neplatny_klic = invalid key, nedostupne = unavailable), in the Loxone text output stav_kod: 0 = OK, 1 = stale data, 401 key, 429 limit, 503 outage. Then stari_min (age in minutes): the data changes three times a day, so overnight it is routinely up to about 16 hours old. A value above 1,800 minutes (30 h) means no new data is being produced.
  • A lost connection may not show in the values. Loxone and other systems keep the last value they read when the server is unreachable. stari_min, however, grows with every successful request. When it stops changing, requests are not getting through.
  • On a 429 or 503 error, wait as long as the Retry-After header says and do not retry immediately.
Home Assistant — data validity and fallback window
template:
  - binary_sensor:
      - name: "ITexSpot data valid"
        unique_id: itexspot_data_platna
        state: >-
          {{ has_value('sensor.itexspot_cena_ted')
             and state_attr('sensor.itexspot_cena_ted', 'stav') == 'ok'
             and (state_attr('sensor.itexspot_cena_ted', 'stari_min') | int(99999)) < 1800 }}

automation:
  - alias: "Boiler: cheap hours, fallback window 1–5 am when data is invalid"
    triggers:
      - trigger: time_pattern
        minutes: "/5"
    actions:
      - variables:
          turn_on: >-
            {% if is_state('binary_sensor.itexspot_data_platna', 'on') %}
              {{ is_state('binary_sensor.itexspot_levno_ted', 'on') }}
            {% else %}
              {{ 1 <= now().hour < 5 }}
            {% endif %}
      - action: "{{ 'switch.turn_on' if turn_on else 'switch.turn_off' }}"
        target:
          entity_id: switch.boiler
The forecast is indicative information, not a guarantee. Your home automation must cope with the API not responding for a while — set a sensible default and watch the age of the data. Details are in the API terms.