Skip to content

Stromligning

Jonas Karlsson edited this page Jan 10, 2025 · 1 revision

To use the Stromligning integration, the following template sensor can be used to create the price input.

- template
  - sensor:
      - name: "Customized Stromligning Sensor"
        state: "{{ states('sensor.stromligning_current_price_vat') }}"
        unique_id: stromligning_template_price_sensor
        unit_of_measurement: "DKK/kWh"
        availability: "{{ states('sensor.stromligning_current_price_vat') not in ['unknown', 'unavailable', None] }}"
        attributes:
          prices_today: >
            {%- set forecast_data = state_attr('sensor.stromligning_current_price_vat', 'prices') %}
            {%- set results = namespace(data=[]) %}
            {%- if forecast_data %}
              {%- for i in forecast_data if as_local(as_datetime(i['start'])).date() == now().date() %}
                {%- set timestamp = as_local(as_datetime(i['start'])).isoformat() %}
                {%- set results.data = results.data + [{'time': timestamp, 'price': i['price']|float}] %}
              {%- endfor %}
            {%- endif %}
            {{ results.data }}
          prices_tomorrow: >
            {%- set tomorrow_available = states('binary_sensor.stromligning_tomorrow_available_vat') == 'on' %}
            {%- set forecast_data = state_attr('binary_sensor.stromligning_tomorrow_available_vat', 'prices') %}
            {%- set results = namespace(data=[]) %}
            {%- if tomorrow_available and forecast_data %}
              {%- for i in forecast_data if as_local(as_datetime(i['start'])).date() == (now() + timedelta(days=1)).date() %}
                {%- set timestamp = as_local(as_datetime(i['start'])).isoformat() %}
                {%- set results.data = results.data + [{'time': timestamp, 'price': i['price']|float}] %}
              {%- endfor %}
            {%- endif %}
            {{ results.data }}