Smart Life (tuya) show wrong temperature

Removed the other init file and confirmed the files are all good. The devices are not found after editing the climate.py as posted.

from:

@property
def current_temperature(self):
“”“Return the current temperature.”""
return self.tuya.current_temperature()

to:

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

I believe there are two issues here:

  1. for current temperature, you would want to use this:

@property
def current_temperature(self):
“”“Return the current temperature.”""
temp = float(self.tuya.current_temperature() or 0)/2
return temp

The issue here is that null is being read as the current temperature, and trying to divide null (which is not the same as 0) by two causes the failure and for the device to not be created when using the custom component.

  1. Current temperature isn’t really what we want here. I have the same costco TCL air conditioner, and the 158 you see is target temperature. It can be halved as well like this:

@property
def target_temperature(self):
“”“Return the temperature we try to reach.”""
“”“temp2 = float(self.tuya.target_temperature() or 0)/2
return temp2"”"
return self.tuya.target_temperature()

However, the issue I’m having, is that mine showed 153 before… and halved is 76.5. But, my AC is set to 68. So maybe someone else knows where those 8.5’ are coming from and/or how to correct them?

1 Like

Hi Im new here, just set the Tuya access, it found my thermostat just right, but it shows bad temperature. For example 23,5 Celsius shows as 235 Celsius. How to solve it, divided by 10?

Hello, which version a HA do you run (as the solution depends if it is before HA version 0.89 or after)… What 's your config ?

HI, I was using the latest version HA 0.92. My config for TUYA was simple, I got only these lines filled:

tuya:
username: MY_TUYA_USERNAME
password: MY_TUYA_PASSWORD
country_code: 420
plattform: smart_life

Then HA auto recognised all my themrostats.

Than you need to create a custom component to modify the code… You have to copy ALL original tuya components into “custom_components/tuya” (you need to create this “tuya” directory), than you modify the climate.py in this newly created directory to change the corresponding temperature (example given by Fraschi earlier in this post if you want to divide the current temperature by 2):

From:

@property
def current_temperature(self):
“”“Return the current temperature.”""
return self.tuya.current_temperature()

to:

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

I hope this is helping…

did this change on 0.92.2 but nothing change still doubling that.

Here are the files I have in my custom_components/tuya:

-rwxr-xr-x 1 homeassistant homeassistant 5050 mai 8 19:16 climate.py
-rwxr-xr-x 1 homeassistant homeassistant 1667 mai 8 19:12 cover.py
-rwxr-xr-x 1 homeassistant homeassistant 2682 mai 8 19:12 fan.py
-rwxr-xr-x 1 homeassistant homeassistant 5039 mai 8 19:12 init.py
-rwxr-xr-x 1 homeassistant homeassistant 3094 mai 8 19:12 light.py
-rw-r–r-- 1 homeassistant homeassistant 196 mai 8 19:12 manifest.json
drwxr-xr-x 2 homeassistant homeassistant 4096 mai 8 19:56 pycache
-rwxr-xr-x 1 homeassistant homeassistant 902 mai 8 19:12 scene.py
-rw-r–r-- 1 homeassistant homeassistant 183 mai 8 19:12 services.yaml
-rwxr-xr-x 1 homeassistant homeassistant 1134 mai 8 19:12 switch.py

I hope this is helping…

PS: init.py and pycache have underscores before and after the filename

Hi Browetd

Can you upload your files? Or give me a download link. Too many copies around. not sure which one working.

You have the safe source of your Tuya code into home assistant (do not download it from internet), tuya is part of the package in home assistant 0.92.2… Mine is located in the following directory (HA is running in a virtual environment on raspberry pi with Python 3.7.2 installed):
/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/tuya/

I just copied all the files from the previous directory to <config_dir>/custom_components/tuya/

and then, make “homeassistant” as owner of these files (command chown) and modified the climate.py program…

Restart HA and then you should have a message in “home-assistant.log” saying that you are using a custom components for tuya, example of the message:
2019-05-11 16:13:22 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for tuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

That’s it !

thanks for the detailed infomation. I need to figure it out how to access /srv/ first. I will give it a go this weekend.

Weird my tuya dimmers also turn off at 12% from home assistant, yet if I connect them directly to the Google home app they work fine, any easy fix for that?

I did exactly what you said but I am now losing numbers after the comma.

2019-06-05%2016_27_48-Home%20Assistant

Thanks for helping!

Hello, it is maybe because the temperature is just 20°C…
Can you also check your climate sensor…Check the following attribute: “target_temp_step”… It is maybe equal to 1°C. so no need to display the value after the comma… I had to change this value in climate.py (same way you changed the current temperature) to get a 0.5°C increment…

Not sure it will help but this is what’s coming in my mind right away… Someone else has surely a better explanation or solution…

What I did:

  1. import constant PRECISION_TENTHS

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

  1. Replace precision:

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

  2. divide all values by 10:
    @property
    def current_temperature(self):
    “”“Return the current temperature.”""
    return self.tuya.current_temperature()/10

    @property
    def target_temperature(self):
    “”“Return the temperature we try to reach.”""
    return self.tuya.target_temperature()/10

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

I now read the right value but I am not able to send target temperature with numbers after the comma.

I will have to make some tests in Fahreneit.

The issue when sending target temperature value is probably related to this:

def set_temperature(self, **kwargs):
    """Set new target temperature."""
    if ATTR_TEMPERATURE in kwargs:
        self.tuya.set_temperature(kwargs[ATTR_TEMPERATURE])

I will have to search about that…

Hi all,
I am on HA 0.96.2 and I also want to set up my Tuya thermostat. I got the same issue that the temperature shows double the actual temp. I tried to follow the above steps but I can’t figure out where the .py files are located. This folder doesn’t seem to exist.

Has this changed in later versions of HA?
Any further help would be appreciated.

Hey. Did you find how to download Tuya files from Rasberry Pi hassio?

Hi, no unfortunately not yet. Any luck on your side?

Hola buenas. A mi no me hace nada. No soy capaz siguiendo lo que habéis puesto. Que el termostato me dé la temperatura correcta. Que puedo hacer?

Hi can I have climate.py??where can I download???