Smart Life (tuya) show wrong temperature

You could change the method following those two to have steps of 0.5 degrees like this:

@property
    def target_temperature_step(self):
        """Return the supported step of target temperature."""
        step = float(self.tuya.target_temperature_step())/2.0
        return step

However, the package used by the Tuya integration (tuyaha) uses int() to send the value to the Tuya API (check here: tuyaha/devices/climate.py#L67).

So changing your code will effectively let you use 0.5-degree steps, but the set temperature will be casted to an int

I believe that to be the reason, I need to find time to do some tests.

Genius, finally made it work. Thanks!!

Hello everyone, I am having the same issue of the current temperature showing 40°C instead of 20°C so I followed the guide and created custom_components\tuya in my config folder, then I copied the files and modified climate.py
The only problem is, what should I do now? Do I have to change something in my configuration.yaml? I really don’t know what I am missing because I don’t even know how to handle custom components with hassio. Thank you

Thanks for the reply, I have not had the time to perform some more tests but will do soon, hopefully someone will get to the bottom of it.

I’ll have to give it another go when summer rolls back around, the AC is in the basement for winter storage right now! Thanks!

I finally found some time to get to the bottom of this problem! Right now, on Home Assistant, I can see the correct room temperature with a 0.5 precision and I am able to set it. Also, min and max target temperatures are now available.

I changed the following:

  • In manifest.json, package tuyaha==0.0.5 becomes tuyaha-float==0.0.7.
  • In __init__.py, add tuyaha = __import__("tuyaha-float") before from tuyaha import TuyaApi.
  • In climate.py:
    • Changed the 2 occurrences of PRECISION_WHOLE to PRECISION_HALVES.
    • Hard-coded min_temp to return 5.0.
    • Hard-coded max_temp to return 35.0.
    • Hard-coded target_temperature_step to return 0.5.
    • Changed target_temperature to return self.tuya.target_temperature()/10.0.
    • Changed current_temperature to return self.tuya.current_temperature()/10.0.

The package tuyaha-float is a fork from the original one, making the needed changes to the API calls. I will make a Pull Request to the package and one to Home Assistant, but this way, anyone wanting to use it, won’t have to wait until this is merged and released.

Still, there’s no solution for the hard-coded min and max temperatures as well as the 2-times or 10-times differences from the current temperature readings from the API.
For example, for my thermostat, the API gives me this data:

{'current_temperature': 195, 'min_temper': 5, 'temperature': 205, 'max_temper': 1220, 'online': True, 'state': 'true'}

Meaning that the target temperature is 20.5 C, the room temperature is 19.5 C, the min temp is 0.5 C (when it should be 5.0 C) and max temp is 122.0 C (when it should be 35.0 C).

3 Likes

Great job!!!
It’s possible to use this configuration, instead of hard-code all those stuff?
With the needed change , of course.
From https://www.home-assistant.io/integrations/generic_thermostat/

climate:
  - platform: generic_thermostat
    name: Study
    heater: switch.study_heater
    target_sensor: sensor.study_temperature
    min_temp: 15
    max_temp: 21
    ac_mode: false
    target_temp: 17
    cold_tolerance: 0.3
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    away_temp: 16
    precision: 0.1

Thanks for your post. Now temperature readings work fine even with 0,5 precision. What about modes? My thermostats are able to work in Manual, Program or Holiday mode in Tuya APP. I cant actually see their current status or set working mode in HA. I can only turn them ON/OFF right now.

And for the underfoor heating theres also floor temperatur available? Thank you.

There is a file to download and the right configuration for tuya thermostat with comma?
I was able to set tuya thermostat without comma only for int natural number , but last posts are confused for not English persons, can someone rewrite easy and clear the step by step guide?

It was so easy to switch from int numbers to float. Just edit custom_components/tuya/climate.py if you have this file already.
Many thanks to rogermiret!

2 Likes

In climate.py :* Changed the 2 occurrences of PRECISION_WHOLE to PRECISION_HALVES

Thanks It works!

Work perfect! Thanks, was very easy , but need also change this?

  • In manifest.json , package tuyaha==0.0.5 becomes tuyaha-float==0.0.7 .
  • In __init__.py , add tuyaha = __import__("tuyaha-float") before from tuyaha import TuyaApi .

Only if you want to fork default tuya component and to have two tuya components (default tuyaha and new tuyaha-float) in your system. I think, you don’t want/need this.

Ciao Antonello, credo di aver capito tu sia italiano. Premetto che ho hassio su raspberry, ho seguito i tuoi step, solo che al riavvio del server l’entità è scomparsa, nonostante nel log mi venga detto che il custom component tuya è stato caricato correttamente. Come posso risolvere?

after upgrade to 0.105.4 I see Temperature set down is double then real Temperature .

I have minimum 18 Celsius
HA show 36 Celsius

the correct file should be /config/custom_components/tuya/climate.py

in the last days, probably after one of the last updates, even the large temperature is seen double. So I also modified these lines:

from

#    @property
#    def target_temperature(self):
#        """Return the temperature we try to reach."""
#        return self.tuya.target_temperature()

to:

@property
def target_temperature(self):
    temp = float(self.tuya.target_temperature())/2
    return temp

Another problem is that the temperature precision is to 1 and not 0.5 so for fix this i added:
PRECISION_TENTHS,

to block

from homeassistant.const import (
ATTR_TEMPERATURE,
PRECISION_WHOLE,
PRECISION_TENTHS,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)

and changed this:

@property
def precision(self):
    """Return the precision of the system."""
    return PRECISION_WHOLE

to

@property
def precision(self):
    """Return the precision of the system."""
    return PRECISION_TENTHS

and divide for 2 also:

@property
def target_temperature_step(self):
    """Return the supported step of target temperature."""
    return self.tuya.target_temperature_step()/2

@Alessandro_Figlioli ma tu hai hai collegato il termostatto con app tuya o smart life?

In English:
You are using tuya app or smart life app?

I changed current temperature to be divided by 2 by copying and changing climate.py in custom_components/tuya . It worked well. My integration worked well until a few weeks ago target temperature also doubled.

Here are new calculations for current and target I have now made:

@property
def current_temperature(self):
    """Return the current temperature. FIXED TO SUPPORT DECIMALS """
    temp = float(self.tuya.current_temperature())/2
    return temp

@property
def target_temperature(self):
    """Return the temperature we try to reach. FIXED TO SUPPORT DECIMALS"""
    temp2 = float(self.tuya.target_temperature())/2
    return temp2

Anyone suggest this to be integrated to next version?
I am also interested to direct integration to device (without tuya). Has anyone done HA integration directly with thermostat devices?
I use MoesHouse BHT-002-GBLW(Wifi) ( aliexpress.com/item/32905181466.html?spm=a2g0s.9042311.0.0.27424c4dRsWynk
and I would like my house be working also if internet is down.

I have the same issue