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 %}