-
-
Save pavax/8d6ed250765d89cb281d4a1762b8d2e8 to your computer and use it in GitHub Desktop.
blueprint: | |
name: Aqara TRV E1 External Temperature Control | |
description: > | |
This automation allows the Aqara TRV E1 Smart Radiator Thermostat to use temperature readings from an external sensor rather than its internal sensor. Whenever the temperature sensor reports a new value, it is sent to the TRV for more accurate climate control. | |
domain: automation | |
source_url: "https://gist.github.com/pavax/8d6ed250765d89cb281d4a1762b8d2e8" | |
input: | |
external_temp_sensor: | |
name: External Temperature Sensor | |
description: Select the temperature sensor that will provide temperature readings to the Aqara TRV. | |
selector: | |
entity: | |
filter: | |
domain: sensor | |
device_class: | |
- temperature | |
aqara_trv_device: | |
name: Aqara TRV Device | |
description: Select the Aqara Smart Radiator Thermostat E1 that will receive the external temperature data. | |
selector: | |
device: | |
multiple: false | |
filter: | |
- integration: mqtt | |
manufacturer: Aqara | |
model: Smart radiator thermostat E1 (SRTS-A01) | |
- integration: mqtt | |
manufacturer: Aqara | |
model: Smart radiator thermostat E1 | |
- integration: mqtt | |
manufacturer: Aqara | |
model: Aqara Smart Radiator thermostat E1 (SRTS-A01) | |
- integration: mqtt | |
manufacturer: Aqara | |
model: Aqara smart radiator thermostat E1 (SRTS-A01) | |
external_temperature_input_name: | |
name: TRV's Input Sensor Name | |
description: Enter a keyword or name used to identify the TRV’s number sensor entity-id, which sets the external temperature value. Defaults to 'external'. | |
selector: | |
text: | |
default: "external" | |
mode: single | |
max_exceeded: silent | |
variables: | |
aqara_trv_device: !input aqara_trv_device | |
external_temp_sensor: !input external_temp_sensor | |
external_temperature_input_name: !input external_temperature_input_name | |
trigger: | |
- trigger: state | |
entity_id: !input external_temp_sensor | |
action: | |
- variables: | |
aqara_trv_device_name: "{{ device_attr(aqara_trv_device, 'name') }}" | |
aqara_trv_select_entity: >- | |
{% set device_entities = device_entities(aqara_trv_device) %} | |
{{ expand(states['select']) | |
| selectattr('entity_id','in', device_entities) | |
| selectattr('attributes.options', 'contains', 'external') | |
| map(attribute='entity_id') | |
| first | |
}} | |
aqara_trv_number_entity: >- | |
{% set device_entities = device_entities(aqara_trv_device) %} | |
{{ expand(states['number']) | |
| selectattr('entity_id','in', device_entities) | |
| selectattr('entity_id', 'contains', external_temperature_input_name) | |
| map(attribute='entity_id') | |
| first | |
}} | |
- if: | |
- condition: template | |
value_template: >- | |
{{ is_state(external_temp_sensor, "unavailable") or is_state(external_temp_sensor, "unknown") }} | |
then: | |
- action: select.select_option | |
target: | |
entity_id: "{{aqara_trv_select_entity}}" | |
data: | |
option: internal | |
- action: system_log.write | |
data: | |
level: error | |
message: External temperature sensor unavailable | |
logger: Aqara TRV | |
- stop: External temperature sensor unavailable | |
- if: | |
- condition: template | |
value_template: "{{ not is_state(aqara_trv_select_entity, 'external')}}" | |
then: | |
- action: select.select_option | |
target: | |
entity_id: "{{aqara_trv_select_entity}}" | |
data: | |
option: external | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 10 | |
milliseconds: 0 | |
- action: number.set_value | |
data: | |
value: >- | |
{{ (states(external_temp_sensor)|float(0)|round(1)) }} | |
target: | |
entity_id: "{{aqara_trv_number_entity}}" |
Hey @pavax !
Is this project left alone and should we take over the blueprint ourselves in HA? Or will you be checking out the deprecation notice at a later date?
@PaulDotterer @LedLeoHA Sorry for the extremely late response and thank you for your suggestions - I updated to blueprint.
@PaulDotterer @LedLeoHA Sorry for the extremely late response and thank you for your suggestions - I updated to blueprint.
Hey @pavax, the new code doesn't work, because it's "playload", but should be "payload"
@LedLeoHA stupid auto-correct on mobile iphone :) thanks I fixed it
Confirming that it works now. Thank you @pavax !
Нow to set the accuracy of temperature setting in thermostat 0.1 degree instead of 0.5 degrees? Hysteresis 1 degree does not work for me.
Hey @pavax,
I would love to use your blueprint. My problem while setting up is that the filter for aqara_trv_device doesn't find the devices. Probably, because m2qtt calls the models: "Aqara Smart Radiator Thermostat E1 (SRTS-A01)" and not "Smart radiator thermostat E1 (SRTS-A01)". Do you see any possibility to adjust the filter to/with wildcards or device type?
Hello, tell me where to insert this script? I go to the HA control panel. then file editor - homeassistant - ??? where next???
I suggest simplifying the code in the part where it interacts with the MQTT service. The integration offers easy access to setting the temperature through number.set_value
.
action: number.set_value
metadata: {}
data:
value: "{{ (states('sensor.sredniaia_temperatura_v_spalne')|float(0)|round(1)) }}"
target:
entity_id: number.0x54ef4410005bae34_external_temperature_input
@almirus Thanks for your suggestion. I updated the script to be based on your suggestion. Can you try it and provide me with some feedback?
@fabibo89 I updated the blueprint to allow you also to fetch a Device with the name "Aqara Smart Radiator Thermostat E1 (SRTS-A01)"
@chEEzys thanks - I updated the blueprint
HI, Can two thermostats be connected to one temperature sensor?
@adamkorski yes
I updated ha and the blueprint to the newest version. When i add a new device, no Aquara TRV devices are in the list.
I updated ha and the blueprint to the newest version. When i add a new device, no Aquara TRV devices are in the list.
@Riemi001 Can you try it again. In the newest version it looks like the model string changed. I updated the blueprint
@adamkorski yes
do I have to do two automations or can I add two thermostats in one?
I updated ha and the blueprint to the newest version. When i add a new device, no Aquara TRV devices are in the list.
@Riemi001 Can you try it again. In the newest version it looks like the model string changed. I updated the blueprint
Thanks, it's working again now
I'd like to point out a fatal flaw with this blueprint, especially for people living in countries where heating is seriously expensive:
What happens if the external temperature sensor fails, and its state becomes unavailable
or unknown
?
In my observation, unavailable
or unknown
turns into 0
when cast/converted to float using {{ (states(external_temp_sensor)|float(0)|round(1)) }}
.
The TRV receives that 0 value, thinks its super cold and opens the valve to 100%, and it stays that way until fixed manually. That actually happened to me while I was out on vacation. That did hurt in my wallet.
Here's a way to fix it. By falling back to the TRV's internal sensor when the external one fails.
actions:
- variables:
# ...
- if:
- condition: template
value_template: >-
{{ is_state(external_temp_sensor, "unavailable") or is_state(external_temp_sensor, "unknown") }}
then:
- action: select.select_option
target:
entity_id: "{{aqara_trv_select_entity}}"
data:
option: internal
- stop: Temperature sensor failed.
# ...
I'd like to point out a fatal flaw with this blueprint, especially for people living in countries where heating is seriously expensive: What happens if the external temperature sensor fails, and its state becomes
unavailable
orunknown
?In my observation,
unavailable
orunknown
turns into0
when cast/converted to float using{{ (states(external_temp_sensor)|float(0)|round(1)) }}
. The TRV receives that 0 value, thinks its super cold and opens the valve to 100%, and it stays that way until fixed manually. That actually happened to me while I was out on vacation. That did hurt in my wallet.Here's a way to fix it. By falling back to the TRV's internal sensor when the external one fails.
actions: - variables: # ... - if: - condition: template value_template: >- {{ is_state(external_temp_sensor, "unavailable") or is_state(external_temp_sensor, "unknown") }} then: - action: select.select_option target: entity_id: "{{aqara_trv_select_entity}}" data: option: internal - stop: Temperature sensor failed. # ...
Thanks for pointing out this flaw- I updated the script.
Does this blueprint have safeguards in place in the event of an HA server restart? For example, by forcing it to restart when HA starts?
Hey could you please update the Blueprint and change the "payload_template" to just "payload". There was a depreciation notice in Home assistant Version 24.8.0 added and it is throwing errors. It can be fixed in the local copy of the blueprint.
Thank you so much!