current_30min_avg: >
{% set now_ts = now() | as_timestamp %}
{% set data_30 = state_attr("sensor.shf_data", "data") | selectattr("Timestamp", "ge", now_ts) | selectattr("Timestamp", "lt", now_ts + 30*60) | list %}
{% if data_30 | length > 0 %}
{{ (data_30 | map(attribute="TotalPrice") | map("float") | sum / data_30 | length) | round(5) }}
{% else %}
0
{% endif %}
current_60min_avg: >
{% set now_ts = now() | as_timestamp %}
{% set data_60 = state_attr("sensor.shf_data", "data") | selectattr("Timestamp", "ge", now_ts) | selectattr("Timestamp", "lt", now_ts + 60*60) | list %}
{% if data_60 | length > 0 %}
{{ (data_60 | map(attribute="TotalPrice") | map("float") | sum / data_60 | length) | round(5) }}
{% else %}
0
{% endif %}
current_120min_avg: >
{% set now_ts = now() | as_timestamp %}
{% set data_120 = state_attr("sensor.shf_data", "data") | selectattr("Timestamp", "ge", now_ts) | selectattr("Timestamp", "lt", now_ts + 60*120) | list %}
{% if data_120 | length > 0 %}
{{ (data_120 | map(attribute="TotalPrice") | map("float") | sum / data_120 | length) | round(5) }}
{% else %}
0
{% endif %}
current_180min_avg: >
{% set now_ts = now() | as_timestamp %}
{% set data_180 = state_attr("sensor.shf_data", "data") | selectattr("Timestamp", "ge", now_ts) | selectattr("Timestamp", "lt", now_ts + 60*180) | list %}
{% if data_180 | length > 0 %}
{{ (data_180 | map(attribute="TotalPrice") | map("float") | sum / data_180 | length) | round(5) }}
{% else %}
0
{% endif %}