Nordpool sensor - lowest price between 00:00 - 06.00

how do i make a sensor (correct time or true/false) so I can start an automation

Nordpool sensor - lowest price between ex. 00:00 - 06.00

i found this (show time and price)


            {% set current_hour = now().hour %}
            {% set departure_time = departure_time + 24 if departure_time <= current_hour else departure_time %}
            {% set ns = namespace(prices = []) %}
            {% set prices = state_attr("sensor.nordpool_kwh_dk1_dkk_3_095_025", "today") | list + state_attr("sensor.nordpool_kwh_dk1_dkk_3_095_025", "tomorrow") | list if state_attr("sensor.nordpool_kwh_dk1_dkk_3_095_025", "tomorrow_valid") else state_attr("sensor.nordpool_kwh_dk1_dkk_3_095_025", "today") %}
            {% set start_index = current_hour | int %}
            {% set end_index = ([departure_time, prices | length] | min - charging_time) | int + 1  %}
            {% for index in range(start_index, end_index) -%}
              {%- set price = prices[index] -%}
                {%- set ns.current_total = 0 -%}
                {%- for i in range(index, index + charging_time) -%} {# loop every hour in charge time#}
                  {%- set ns.current_total = ns.current_total + prices[i] | float(0) -%}
                {%-endfor -%}
              {% set ns.prices = ns.prices + [ns.current_total] -%}
            {% endfor %}
            {% if ns.prices | length  > 0 %}
              kl {{'{:0>2}'.format((ns.prices.index(ns.prices | min) + start_index) % 24)}},  {{ "%.2f"|format(ns.prices | min) }}kr
            {% endif %}

Have a look here…

I have seen it, but i dont know how to make my sensor :-/

did you manage to find a solution?

I’m looking for help on something similar: “Cheapest price between sunrise and sunset” ?

I can have it to index based on the entire day, but would like to limit the sensor to look at hours only between sunrise and sunset.

This would be a great automation to start “daymode” on the thermostats.
Find the cheapest hour between 05.00 and 09.00… Or something like that.

How about this?
Cheapest 2 hours in first 6 hours of raw_today of the nordpool integration entity

  - platform: template
    sensors:
      cheapest_hours_0_to_6:
        value_template: >-
         {% set l1=state_attr('sensor.nordpool', 'raw_today')[:6]|sort(attribute='value') %}
         {{
           (now() >= l1[0].start and now() <= l1[0].end)
           or (now() >= l1[1].start and now() <= l1[1].end)
         }}