sure, it’s not pretty, dunno too much about HA scripting syntax and HA messed up the formatting a bit. If I did it properly it should be following the load balancing usecases as described in this document https://assets.danfoss.com/documents/202524/AU417130778872en-000101.pdf , section 2.2. it runs at 15 minute intervals.
alias: 2F-SCR-TRV update average load Living - logic
sequence:
- service: number.set_value
data_template:
value: >
{% set ns = namespace(sum = 0, count = 0, avg = 0) %} {% if
(states('sensor.2f_trv_living1_load_estimate') | float > -500) %}
{% if ((as_timestamp(now())
- as_timestamp(states.sensor['2f_trv_living1_load_estimate'].last_updated ) ) | float | round(0)
< 5400 ) %}
{% set ns.sum = ns.sum + states('sensor.2f_trv_living1_load_estimate') | float %}
{% set ns.count = ns.count + 1 %}
{% endif %}
{% endif %} {% if (states('sensor.2f_trv_living2_load_estimate') | float
> -500) %}
{% if ((as_timestamp(now())
- as_timestamp(states.sensor['2f_trv_living2_load_estimate'].last_updated ) ) | float | round(0)
< 5400 ) %}
{% set ns.sum = ns.sum + states('sensor.2f_trv_living2_load_estimate') | float %}
{% set ns.count = ns.count + 1 %}
{% endif %}
{% endif %} {% if (states('sensor.2f_trv_living3_load_estimate') | float
> -500) %}
{% if ((as_timestamp(now())
- as_timestamp(states.sensor['2f_trv_living3_load_estimate'].last_updated ) ) | float | round(0)
< 5400 ) %}
{% set ns.sum = ns.sum + states('sensor.2f_trv_living3_load_estimate') | float %}
{% set ns.count = ns.count + 1 %}
{% endif %}
{% endif %} {% if ns.count >0 %}
{% set ns.avg = ns.sum/ns.count %}
{% endif %} {{ ns.avg | round(0) }}
target:
entity_id:
- number.2f_trv_living1_load_room_mean
- number.2f_trv_living2_load_room_mean
- number.2f_trv_living3_load_room_mean
mode: single