Skip to content

Instantly share code, notes, and snippets.

@jamesonuk
Last active April 25, 2026 17:33
Show Gist options
  • Select an option

  • Save jamesonuk/83111e89e6a05aa728acad3524494be0 to your computer and use it in GitHub Desktop.

Select an option

Save jamesonuk/83111e89e6a05aa728acad3524494be0 to your computer and use it in GitHub Desktop.
Set Sonoff TRV external temperature from external sensor
blueprint:
name: TRV External Temp
description: >
Sets the external temperature on a Sonoff TRV and ensures it is configured
to use the external sensor. Select the TRV as a device — entities are
resolved automatically.
domain: automation
source_url: https://gist.github.com/jamesonuk/83111e89e6a05aa728acad3524494be0
input:
trv_device:
name: TRV Device
description: The Sonoff TRV device to control
selector:
device:
filter:
- manufacturer: "SONOFF"
model_id: "TRVZB"
entity:
- domain: number
device_class: temperature
temp_sensors:
name: Temp Sensors
description: External sensor(s) whose readings are pushed to the TRV
selector:
entity:
multiple: true
filter:
domain: sensor
device_class: temperature
mode: restart
triggers:
- trigger: state
entity_id: !input temp_sensors
actions:
- variables:
trv_device: !input trv_device
trv_temp_entity: >
{% set ns = namespace(result='') %}
{% for eid in device_entities(trv_device) %}
{% if eid.split('.')[0] == 'number'
and state_attr(eid, 'device_class') == 'temperature' %}
{% set ns.result = eid %}
{% endif %}
{% endfor %}
{{ ns.result }}
trv_mode_entity: >
{% set ns = namespace(result='') %}
{% for eid in device_entities(trv_device) %}
{% if eid.split('.')[0] == 'select' %}
{% set opts = state_attr(eid, 'options') %}
{% if opts and 'internal' in opts and 'external' in opts %}
{% set ns.result = eid %}
{% endif %}
{% endif %}
{% endfor %}
{{ ns.result }}
- if:
- condition: template
value_template: >
{{ trv_mode_entity != ''
and states(trv_mode_entity) == 'internal' }}
then:
- action: select.select_option
target:
entity_id: "{{ trv_mode_entity }}"
data:
option: "external"
- if:
- condition: template
value_template: >
{{ trv_temp_entity != ''
and (trigger.to_state.state | float
- states(trv_temp_entity) | float) | abs >= 0.1 }}
then:
- action: number.set_value
target:
entity_id: "{{ trv_temp_entity }}"
data:
value: "{{ trigger.to_state.state }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment