- sensor:
- name: SHF Control Factor +-1
...
today_values: >
{% set output = namespace(value=[]) %}
{% for pnow in state_attr("sensor.shf_electricity_price_now", "today_prices") %}
{% set pmin = state_attr("sensor.shf_electricity_price_now", "today_min") | float %}
{% set pmax = state_attr("sensor.shf_electricity_price_now", "today_max") |
{% set value = max(min((2*(pmax - pnow) / (pmax - pmin)-1) * states('input_number.shf_control_function_factor') | float,1),-1) %}
...
I believe that it would never be the case in real world, however, for the sake of getting rid of the error message I suggest following fix:
{% set pmin = state_attr("sensor.shf_electricity_price_now", "today_min") | float %}
{% set pmax = state_attr("sensor.shf_electricity_price_now", "today_max") | float %}
{% if pmax == pmin %}
{% set value = 1 %}
{% else %}
{% set value = max(min((2*(pmax - pnow) / (pmax - pmin)-1) * states('input_number.shf_control_function_factor') | float,1),-1) %}
{% endif %}