Hi David,
Thanks, this is great coding! I further adjusted it, so I also know which area is requesting heating.
This is my sensor that is calculating the right heating delta.
I did set it up in the (old fashioned but reliable) configuration.yaml. If I use the UI, I received an error that the entity state is longer than 255 character.
- sensor:
- name: Verwarming - ruimte met grootste delta
unique_id: heating_deltas
state: >-
{% set ns = namespace(items=[]) %}
{% for clim in states.climate
if clim.entity_id.startswith('climate.vtherm') and clim.state == 'heat' %}
{% set clim_temp = clim.attributes.temperature | float(18) %}
{% set clim_curr_temp = clim.attributes.current_temperature | float(18) %}
{% set delta = (clim_temp - clim_curr_temp) | round(1, 'ceil') %}
{% if delta > 0 %}
{% set area = area_name(clim.entity_id) %}
{% set ns.items = ns.items + [{
"area": area,
"entity_id": clim.entity_id,
"target": clim_temp,
"curr": clim_curr_temp,
"delta": delta
}] %}
{% endif %}
{% endfor %}
{% set valid_items = ns.items %}
{{ (
valid_items
| max(attribute='delta')
if valid_items
else {
"area": "",
"entity_id": "",
"target": 18.0,
"curr": 18.0,
"delta": 0
}
)
| to_json
}}
The code above assumes that all climate entities involved should start with “vtherm” and are heating.
I created three additional sensors to retrieve the current and target temperature (this is exactly as you did) and the area of the thermostat that triggers my heating:
- sensor:
- name: Virtual Heating Setpoint
unique_id: heating_virtual_setpoint
state: "{{ (states('sensor.heating_deltas') | from_json).target }}"
unit_of_measurement: "°C"
- sensor:
- name: Virtual Heating Temperature
unique_id: heating_virtual_temperature
state: "{{ (states('sensor.heating_deltas') | from_json).curr }}"
unit_of_measurement: "°C"
- sensor:
- name: Virtual Heating Area
unique_id: heating_virtual_area
state: "{{ (states('sensor.heating_deltas') | from_json).area }}"
I also created an automation that would control my OpenTherm (DIYLESS) thermostat with the correct current and target temperature. It not only sends any change to above sensors directly to the thermostat, but will also do it every 20 seconds (so the thermostat does not go in error when no updates are received).
alias: Send current and target temperature to DIYLESS Thermostat
description: ""
triggers:
- trigger: time_pattern
seconds: /20
- trigger: state
entity_id:
- sensor.heating_virtual_setpoint
- sensor.heating_virtual_temperature
actions:
- alias: Publish current temperature to OpenTherm
action: mqtt.publish
metadata: {}
data:
evaluate_payload: false
qos: "0"
retain: false
topic: diyless_thermostat/cmnd/things/thermostat/properties/temperature
payload: |
{{
states('sensor.heating_virtual_temperature') | float
}}
enabled: true
- alias: Publish target temperature to OpenTherm
action: climate.set_temperature
metadata: {}
data:
temperature: "{{ states('sensor.heating_virtual_setpoint') | float }}"
hvac_mode: heat
target:
entity_id: climate.diyless_thermostat_1_central_heating