Sorry for the delayed answer. Here comes a more comprehensive answer.
#1 - Add a “Helper”
I use a dropdown heller that looks like this:
#2 - In configuration.yaml add:
sensor:
- platform: template
sensors:
nordpool_eo4_on_hours:
friendly_name: "Nordpool EO4 Configurable On"
unit_of_measurement: 'SEK/kWh'
value_template: >
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) }}
attribute_templates:
below_config_value_now: >
{% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'current_price') <=
average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) %}
True
{% else %}
False
{% endif %}
current_price: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'current_price') }}
today: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') }}
tomorrow_valid: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') }}
tomorrow: >
{% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') %}
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) }}
{% else %}
[]
{% endif %}
#3 - My automation for “cheap” looks like this
Then you add one more for “expensive” where your use “above” instead of “below”.
HTH/Marcus