{%- set raw_today = state_attr(spot, 'raw_today') %} {%- set x = namespace() %} {%- set x.max_price = -1000 %} {%- for hour in range(4,11) %} {%- if raw_today[hour].value > x.max_price %} {%- set x.max_price = raw_today[hour].value %} {%- set x.max_hour = hour %} {%- endif %} {%- endfor %} {{x.max_hour}}