Smart Life (tuya) show wrong temperature

The patch from Smart Life (tuya) show wrong temperature - #244 by midstar still works as of version 2023.12.0

Hi all!
I solved this bug in a different way:
I created a thermostat (it requires a switch and a sensor) and through automation made communication between these thermostats
(Tuya integration thermostat <=> Manually created thermostat)
If, of course, people are interested, I can post detailed instructions for this “crutch”…
The result is as follows:

Прикольно. :+1: Покажи как.

I want to say right away that the solution, of course, has its pros and cons.
I think it will not be suitable for all devices or additional configuration modification will be required.

I will write out the instructions in detail:

  1. In order to create a thermostat, we need to create a sensor that displays the real (corrected) temperature and a switch that displays the operating mode (idle/heating)

configuration.yaml:

sensor:
  - platform: template
    sensors:
      thermostat_current_temperature:
        unique_id: "thermostat_current_temperature"
        friendly_name: "Thermostat current temperature"
        unit_of_measurement: "°C"
        value_template: "{{ state_attr('climate.thermostat_hot_floor', 'current_temperature') * 5.0 }}"

switch:
  - platform: template
    switches:
      thermostat_heating_switch:
        unique_id: "thermostat_heating_switch"
        friendly_name: "Обогрев теплого пола" 
        icon_template: >
          {% if  is_state('climate.thermostat_hot_floor','heat_cool') %}
            mdi:fire
          {% else %}
            mdi:fire-off
          {% endif %}
        value_template: "{{ is_state('climate.thermostat_hot_floor','heat_cool') }}"
        turn_on:
        turn_off:
  1. Create a new thermostat and specify the sensor and switch that we created in step 1.

configuration.yaml:

climate:
  - platform: generic_thermostat
    unique_id: "thermostat_hot_floor_fix"
    name: "Теплый пол (термостат)"
    heater: switch.thermostat_heating_switch
    target_sensor: sensor.thermostat_current_temperature
    min_temp: 5
    max_temp: 35
    ac_mode: false
    target_temp: 18
    initial_hvac_mode: "off"
    precision: 0.5
  1. We create automation that will perform the functions of turning on/off heating and changing temperature.
    I created automation through the UI, I’ll attach the script below:
alias: Теплый пол (tuya <-> thermostat)
description: ""
trigger:
  - alias: Heat (tuya -> thermostat)
    platform: state
    entity_id:
      - climate.thermostat_hot_floor
    to: heat_cool
    id: heat_tuya_thermostat
  - alias: Off (tuya -> thermostat )
    platform: state
    entity_id:
      - climate.thermostat_hot_floor
    to: "off"
    id: off_tuya_thermostat
  - alias: Set temperature (tuya -> thermostat)
    platform: state
    entity_id:
      - climate.thermostat_hot_floor
    id: set_temperature_tuya_thermostat
    attribute: temperature
  - platform: state
    entity_id:
      - climate.thermostat_hot_floor_fix
    to: heat
    alias: Heat (thermostat -> tuya)
    id: heat_thermostat_tuya
  - alias: Off (thermostat -> tuya)
    platform: state
    entity_id:
      - climate.thermostat_hot_floor_fix
    to: "off"
    id: off_thermostat_tuya
  - alias: Set temperature (thermostat -> tuya)
    platform: state
    entity_id:
      - climate.thermostat_hot_floor_fix
    id: set_temperature_thermostat_tuya
    attribute: temperature
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - heat_tuya_thermostat
        sequence:
          - service: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: heat
            target:
              entity_id: climate.thermostat_hot_floor_fix
      - conditions:
          - condition: trigger
            id:
              - off_tuya_thermostat
        sequence:
          - service: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: "off"
            target:
              entity_id: climate.thermostat_hot_floor_fix
      - conditions:
          - condition: trigger
            id:
              - heat_thermostat_tuya
        sequence:
          - service: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: heat_cool
            target:
              device_id: 64e3bce9f9789856118b4eb646a5d537
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - off_thermostat_tuya
        sequence:
          - service: climate.set_hvac_mode
            metadata: {}
            data:
              hvac_mode: "off"
            target:
              device_id: 64e3bce9f9789856118b4eb646a5d537
      - conditions:
          - condition: trigger
            id:
              - set_temperature_tuya_thermostat
          - condition: template
            value_template: >-
              {{ (state_attr('climate.thermostat_hot_floor', 'temperature') *
              5.0) != state_attr('climate.thermostat_hot_floor_fix',
              'temperature') }}
        sequence:
          - service: climate.set_temperature
            metadata: {}
            data:
              temperature: >-
                {{ state_attr('climate.thermostat_hot_floor', 'temperature') *
                5.0 }}
            target:
              entity_id: climate.thermostat_hot_floor_fix
      - conditions:
          - condition: trigger
            id:
              - set_temperature_thermostat_tuya
          - condition: template
            value_template: >-
              {{ (state_attr('climate.thermostat_hot_floor', 'temperature') *
              5.0) != state_attr('climate.thermostat_hot_floor_fix',
              'temperature') }}
        sequence:
          - service: climate.set_temperature
            metadata: {}
            data:
              temperature: >-
                {{ state_attr('climate.thermostat_hot_floor_fix', 'temperature')
                / 5.0 }}
            target:
              entity_id: climate.thermostat_hot_floor
mode: single

For everything described above to work, you need to replace the following values:
1. ‘64e3bce9f9789856118b4eb646a5d537’ => device_id in the home assistant of your device from tuya
2. ‘climate.thermostat_hot_floor’ => unique_id of your device from tuya

As a result, you get a thermostat “climate.thermostat_hot_floor_fix” which shows the correct values.

2 Likes

That’s alot of yaml! :slight_smile:
I have 5 thermostats in HA, and even more waiting for upgrade.

Just use tuya local and everything will work fine

Hi Roman,
Where did you get the ID? I guess that’s my problem. I have two different IDs, but I didn’t manage to make the automation work. I also did the temperature change a long time ago and it is similar.
Thanks

Hello,

I have 2 type of thermostats at my home, some of those with 0.5 multiplier, some of those with 0.1. how I can use them both?

Ed

Thank you very much for this work! Having figured it out, made a few adjustments, I added my 8 thermostats and now everything works and is displayed correctly! Well done!