Target temperature adjustment depending on second temperature sensor

Tags: #<Tag:0x00007fc4016e0380> #<Tag:0x00007fc4016e01f0>

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Moin!

Sets target temperature depending on second temperature sensor. This blueprint is inspired by this blueprint Tado set offset using separate temperature sensor created by @Sanderma . Since not all thermostat devices have an configurable offset, this blueprint sets the target temperature of the thermostat device depending on a given target temperature and a second temperature sensor.

blueprint:
  name: Target temperature adjustment depending on second temperature sensor
  description: >
    Sets target temperature depending on second temperature sensor.
    This blueprint is inspired by this blueprint https://community.home-assistant.io/t/tado-set-offset-using-separate-temperature-sensor/288515
    created by Sanderma. Since not all thermostat devices have an configurable
    offset, this blueprint sets the target temperature of the thermostat device
    depending on a given target temperature and a second temperature sensor.
  domain: automation
  input:
    temperature_sensor:
      name: Temperature sensor
      description: This sensor will be used as the source.
      selector:
        entity:
          domain: sensor
          device_class: temperature
    thermostat:
      name: Thermostat
      description: The thermostat to set target temperature
      selector:
        entity:
          domain: climate
    target_temperature:
      name: Target temperature
      description: Target temperature of the thermostat
      selector:
        number:
          min: 5
          max: 30
          step: 0.5
          unit_of_measurement: "°C"
      default: 21
          
variables:
  thermostat: !input thermostat
  temperature_sensor: !input temperature_sensor
  target_temperature: !input target_temperature
  actual_temperature: "{{ states(temperature_sensor) | float }}"
  calculated_adjustment: "{{ target_temperature - actual_temperature }}"
  calculated_target_temperature: "{{ ( ( ( target_temperature + calculated_adjustment ) * 2 ) | round ) / 2 }}"

trigger:
- platform: state
  entity_id: !input thermostat
  attribute: "{{ current_temperature_attribute }}"
- platform: state
  entity_id: !input temperature_sensor
  
condition: "{{ calculated_adjustment != 0 }}"

action:
- service: system_log.write
  data:
    message: >
      {{ thermostat }} has temp difference of {{ calculated_adjustment }}. Setting target temperature to {{ calculated_target_temperature }}
    level: info
    logger: blueprints.nevesenin.target_temperature_adjustment
- service: system_log.write
  data:
    message: >
      thermostat: {{ thermostat }},
      temperature_sensor: {{ temperature_sensor }},
      target_temperature: {{ target_temperature }},
      actual_temperature: {{ actual_temperature }},
      calculated_adjustment: {{ calculated_adjustment }},
      calculated_target_temperature: {{ calculated_target_temperature }}
    level: debug
    logger: blueprints.nevesenin.target_temperature_adjustment
- service: climate.set_temperature
  data:
    temperature: "{{ calculated_target_temperature }}"
    entity_id: "{{ thermostat }}"
mode: single
1 Like

awesome thanks! although this will not work with zigbee related trv’s right?

Hi!
I use this with https://www.zigbee2mqtt.io/devices/SPZB0001.html#eurotronic-spzb0001 and https://www.zigbee2mqtt.io/devices/TT001ZAV20.html#tuya-tt001zav20 via zigbee2mqtt.

This Blueprint does not work for me, it seems the temperature unit is had coded to Celsius and since my system uses Fahrenheit HA throws errors. Is this something that can be changed?

I need to make some guessings here b/c in theory this should also work for Fahrenheit. I could imagine, that the temperature ranges of your devices are different (not 5-30). Also I don’t know if 0.5 steps are possible. If you could provide these information, I’ll try to create a Fahrenheit blueprint when I have time.

Here is the error in the log I get.

Logger: homeassistant.components.automation.target_temperature_adjustment_depending_on_second_temperature_sensor
Source: components/nest/climate_sdm.py:312
Integration: Automation (documentation, issues)
First occurred: 6:00:21 AM (2 occurrences)
Last logged: 6:00:21 AM

Target temperature adjustment depending on second temperature sensor: Error executing script. Unexpected error for call_service at pos 3: Error from API: 400: INVALID_ARGUMENT: Temperature setpoint is out of range [10.000000, 32.222301] in FAHRENHEIT.: Bad Request
While executing automation automation.target_temperature_adjustment_depending_on_second_temperature_sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 80, in _raise_for_status
    resp.raise_for_status()
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 1000, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://smartdevicemanagement.googleapis.com/v1/enterprises/5826d294-f97d-4963-add2-df3c4b3435b5/devices/AVPHwEvbYAV1sT9RiutrVlNGHM2kQN9k8bxq9GWGFkKgRDoOzfyVNpvB0jI1mLGzvLOskm0lfLkyDvElbUg5QPyv-ZcaMw:executeCommand')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 563, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 726, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 548, in async_service_temperature_set
    await entity.async_set_temperature(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nest/climate_sdm.py", line 312, in async_set_temperature
    await trait.set_cool(temp)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/thermostat_traits.py", line 132, in set_cool
    return await self._cmd.execute(data)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/traits.py", line 23, in execute
    return await self._auth.post(f"{self._device_id}:executeCommand", json=data)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 73, in post
    return await AbstractAuth._raise_for_status(resp)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 85, in _raise_for_status
    raise ApiException(": ".join(detail)) from err
google_nest_sdm.exceptions.ApiException: Error from API: 400: INVALID_ARGUMENT: Temperature setpoint is out of range [10.000000, 32.222301] in FAHRENHEIT.: Bad Request

here is the automation trace.

{
  "trace": {
    "last_step": "action/2",
    "run_id": "222",
    "state": "stopped",
    "script_execution": "error",
    "timestamp": {
      "start": "2021-05-02T11:00:20.943854+00:00",
      "finish": "2021-05-02T11:00:21.802982+00:00"
    },
    "domain": "automation",
    "item_id": "1619953140091",
    "error": "Error from API: 400: INVALID_ARGUMENT: Temperature setpoint is out of range [10.000000, 32.222301] in FAHRENHEIT.: Bad Request",
    "trigger": null,
    "trace": {
      "trigger": [
        {
          "path": "trigger",
          "timestamp": "2021-05-02T11:00:20.944524+00:00",
          "changed_variables": {
            "trigger": {
              "platform": null
            },
            "thermostat": "climate.rio_nest",
            "temperature_sensor": "sensor.master_bedroom_sensor_temp",
            "target_temperature": 22,
            "actual_temperature": 77.5,
            "calculated_adjustment": -55.5,
            "calculated_target_temperature": -33.5
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2021-05-02T11:00:20.945673+00:00",
          "changed_variables": {
            "context": {
              "id": "7afcb20eb7ae43751ec7951e501e244c",
              "parent_id": "6e8d93cf2034130befd35a04eacca22d",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "system_log",
              "service": "write",
              "service_data": {
                "message": "climate.rio_nest has temp difference of -55.5. Setting target temperature to -33.5",
                "level": "info",
                "logger": "blueprints.nevesenin.target_temperature_adjustment"
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2021-05-02T11:00:20.951904+00:00",
          "result": {
            "params": {
              "domain": "system_log",
              "service": "write",
              "service_data": {
                "message": "thermostat: climate.rio_nest, temperature_sensor: sensor.master_bedroom_sensor_temp, target_temperature: 22, actual_temperature: 77.5, calculated_adjustment: -55.5, calculated_target_temperature: -33.5",
                "level": "debug",
                "logger": "blueprints.nevesenin.target_temperature_adjustment"
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2021-05-02T11:00:20.952812+00:00",
          "error": "Error from API: 400: INVALID_ARGUMENT: Temperature setpoint is out of range [10.000000, 32.222301] in FAHRENHEIT.: Bad Request",
          "result": {
            "params": {
              "domain": "climate",
              "service": "set_temperature",
              "service_data": {
                "temperature": -33.5,
                "entity_id": "climate.rio_nest"
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "variables": {
        "thermostat": "climate.rio_nest",
        "temperature_sensor": "sensor.master_bedroom_sensor_temp",
        "target_temperature": 22,
        "actual_temperature": "{{ states(temperature_sensor) | float }}",
        "calculated_adjustment": "{{ target_temperature - actual_temperature }}",
        "calculated_target_temperature": "{{ ( ( ( target_temperature + calculated_adjustment ) * 2 ) | round ) / 2 }}"
      },
      "trigger": [
        {
          "platform": "state",
          "entity_id": "climate.rio_nest",
          "attribute": "{{ current_temperature_attribute }}"
        },
        {
          "platform": "state",
          "entity_id": "sensor.master_bedroom_sensor_temp"
        }
      ],
      "condition": "{{ calculated_adjustment != 0 }}",
      "action": [
        {
          "service": "system_log.write",
          "data": {
            "message": "{{ thermostat }} has temp difference of {{ calculated_adjustment }}. Setting target temperature to {{ calculated_target_temperature }}\n",
            "level": "info",
            "logger": "blueprints.nevesenin.target_temperature_adjustment"
          }
        },
        {
          "service": "system_log.write",
          "data": {
            "message": "thermostat: {{ thermostat }}, temperature_sensor: {{ temperature_sensor }}, target_temperature: {{ target_temperature }}, actual_temperature: {{ actual_temperature }}, calculated_adjustment: {{ calculated_adjustment }}, calculated_target_temperature: {{ calculated_target_temperature }}\n",
            "level": "debug",
            "logger": "blueprints.nevesenin.target_temperature_adjustment"
          }
        },
        {
          "service": "climate.set_temperature",
          "data": {
            "temperature": "{{ calculated_target_temperature }}",
            "entity_id": "{{ thermostat }}"
          }
        }
      ],
      "mode": "single",
      "id": "1619953140091",
      "alias": "Target temperature adjustment depending on second temperature sensor",
      "description": ""
    },
    "blueprint_inputs": {
      "id": "1619953140091",
      "alias": "Target temperature adjustment depending on second temperature sensor",
      "description": "",
      "use_blueprint": {
        "path": "nevesenin/target_temperature_adjustment.yaml",
        "input": {
          "temperature_sensor": "sensor.master_bedroom_sensor_temp",
          "thermostat": "climate.rio_nest",
          "target_temperature": 22
        }
      }
    },
    "context": {
      "id": "7afcb20eb7ae43751ec7951e501e244c",
      "parent_id": "6e8d93cf2034130befd35a04eacca22d",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Target temperature adjustment depending on second temperature sensor",
      "message": "has been triggered",
      "source": null,
      "entity_id": "automation.target_temperature_adjustment_depending_on_second_temperature_sensor",
      "context_id": "7afcb20eb7ae43751ec7951e501e244c",
      "when": "2021-05-02T11:00:20.944650+00:00",
      "domain": "automation"
    }
  ]
}