Smart Life (tuya) show wrong temperature

This issue is back again in tuya v2, however you can just use it by patching it.

This is a test repo that works with current HA stable: GitHub - 3v1n0/tuya-ha-hacks

Main dirty changes needed are:

commit b85573b19849e4f2c3d0d50e0291b9585aa71784
Author: Marco Trevisan (Treviño) <[email protected]>
Date:   Mon Nov 1 19:06:23 2021 +0100

    climate: Also use Upper temp as current temperature

diff --git a/climate.py b/climate.py
index bd3afd8..e6aaf7b 100644
--- a/climate.py
+++ b/climate.py
@@ -144,9 +144,9 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
         # use whatever the device is set to, with a fallback to celsius.
         if all(
             dpcode in device.status
-            for dpcode in (DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F)
+            for dpcode in (DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F, DPCode.UPPER_TEMP)
         ) or all(
-            dpcode in device.status for dpcode in (DPCode.TEMP_SET, DPCode.TEMP_SET_F)
+            dpcode in device.status for dpcode in (DPCode.TEMP_SET, DPCode.TEMP_SET_F, DPCode.UPPER_TEMP)
         ):
             self._attr_temperature_unit = TEMP_CELSIUS
             if any(
@@ -198,7 +198,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
         # Determine dpcode to use for getting the current temperature
         if all(
             dpcode in device.status
-            for dpcode in (DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F)
+            for dpcode in (DPCode.TEMP_CURRENT, DPCode.TEMP_CURRENT_F, DPCode.UPPER_TEMP)
         ):
             self._current_temperature_dpcode = DPCode.TEMP_CURRENT
             if self._attr_temperature_unit == TEMP_FAHRENHEIT:
@@ -207,6 +207,8 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
             self._current_temperature_dpcode = DPCode.TEMP_CURRENT
         elif DPCode.TEMP_CURRENT_F in device.status:
             self._current_temperature_dpcode = DPCode.TEMP_CURRENT_F
+        elif DPCode.UPPER_TEMP in device.status:
+            self._current_temperature_dpcode = DPCode.UPPER_TEMP
 
         # If we have a current temperature dpcode, get the integer type data
         if (
diff --git a/const.py b/const.py
index a9f7afb..f0f1ecd 100644
--- a/const.py
+++ b/const.py
@@ -298,6 +298,7 @@ class DPCode(str, Enum):
     TEMP_VALUE = "temp_value"  # Color temperature
     TEMP_VALUE_V2 = "temp_value_v2"
     TEMPER_ALARM = "temper_alarm"  # Tamper alarm
+    UPPER_TEMP = "upper_temp"
     UV = "uv"  # UV sterilization
     VA_BATTERY = "va_battery"
     VA_HUMIDITY = "va_humidity"

And

commit e46a5922b9e5630eb2e5702557ccc9803c1289e1
Author: Marco Trevisan (Treviño) <[email protected]>
Date:   Mon Nov 1 19:11:53 2021 +0100

    climate: Adjust temperature dividers to support my setup

diff --git a/climate.py b/climate.py
index e6aaf7b..e0943ac 100644
--- a/climate.py
+++ b/climate.py
@@ -191,8 +191,8 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
             )
             self._attr_supported_features |= SUPPORT_TARGET_TEMPERATURE
             self._set_temperature_type = type_data
-            self._attr_max_temp = type_data.max_scaled
-            self._attr_min_temp = type_data.min_scaled
+            self._attr_max_temp = type_data.max_scaled * 10.0 / 2.0
+            self._attr_min_temp = type_data.min_scaled * 10.0 / 2.0
             self._attr_target_temperature_step = type_data.step_scaled
 
         # Determine dpcode to use for getting the current temperature
@@ -367,9 +367,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
             [
                 {
                     "code": self._set_temperature_dpcode,
-                    "value": round(
-                        self._set_temperature_type.scale_value(kwargs["temperature"])
-                    ),
+                    "value": round(float(kwargs["temperature"]) * 2.0),
                 }
             ]
         )
@@ -387,7 +385,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
         if temperature is None:
             return None
 
-        return self._current_temperature_type.scale_value(temperature)
+        return self._current_temperature_type.scale_value(temperature) / 2.0
 
     @property
     def current_humidity(self) -> int | None:
@@ -411,7 +409,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
         if temperature is None:
             return None
 
-        return self._set_temperature_type.scale_value(temperature)
+        return self._set_temperature_type.scale_value(temperature) * 10 / 2.0
 
     @property
     def target_humidity(self) -> int | None:
2 Likes

Hi!
That´s great news, please could you gave us short guide how to change it in config?
I have the same problem:


Together with no current temp. state.

There’s no extra config (other than the default one).

Just clone https://github.com/3v1n0/tuya-ha-hacks in your custom_components folder so that it’s called tuya (to override the default one):

git clone https://github.com/3v1n0/tuya-ha-hacks.git tuya

And on reboot, the custom component will be used instead of default one. Adjust the hardcoded multiplier (TUYA_TEMPERATURE_MULTIPLIER) in case yours doesn’t use values multiplied by 2.

10 Likes

@3v1n0 Thank you! Did you submit fixes to mainstream repo?

1 Like

All my Tuya devices disappeared (disconnected) from HA yesterday after I updated to core 2021.11.1 did anyone else have this problem for the TuyaV2 integration? Once I rolled back to the previous day’s HA back up everything as working again.

I did mention that it would be the way (even though my code is just a quick hack, not something merge-able), but it requires custom codepaths for devices with product_id that is IAYz2WK1th0cMLmL (please check if yours match).

So, I can imagine that upstream is reluctant in doing that just for one specific kind (that tuya explicitly didn’t support), even though that’s probably the most sold tuya thermostat ever…

I’ve updated the branch to make it look only like an heater given that this is something true for this, and the scheduler card didn’t support properly the heater/cooler mode.


BTW, I think that another way to use it without the custom integration above would be to just define a custom heater via:

template:
  - sensor:
      - name: "Tuya thermostat fixed temperature"
        unique_id: tuya_thermostat_temperature_fixed
        unit_of_measurement: "°C"
        state: '{ (states('sensor.original_tuya_temperature_sensor_name')) | float) / 2.0 }' # use your multiplier here

climate:
  - platform: generic_thermostat
    name: Tuya Heater
    heater: climate.your_tuya_thermostat_id
    target_sensor: sensor.tuya_thermostat_temperature_fixed
    min_temp: 5
    max_temp: 35
    ac_mode: false
    target_temp: 17
    min_cycle_duration:
      seconds: 5
    initial_hvac_mode: "off"
    away_temp: 12
    precision: 0.5

Then, set the actual thermostat temperature value to an high value, and just use this manual thermostat to handle it. Sad but should work (check the syntax, as I didn’t test it fully).

This worked great, thanks!

I have a MOES BHT-002 thermostat which uses the SmartLife app. It used to work with the old TUYA integration but I now have several problems:

  • Temperatures (readings and settings) are out by a factor of a fifth
  • Temperatures never update. When I add the TUYA 2 integration (I’ve added and removed it several times to see if I can sort it out at all to no avail), the temperature seems to be read but then no more.
  • I can’t send any commands to the thermostat - I can’t set a temperature, switch it off, etc.
    Some of the suggestions above may help (I’ve already set up a sensor to multiply the temperature by 5) but not everything. Appreciate any suggestions.

Old Tuya
It will work, I don’t know how long
Edit:
Tuya pushed back the timeline for sunsetting the old API with 6 months; but it was too late for us to change course and ship the old integration.

https://github.com/andrey-yantsen/home-assistant-tuya-old

Thanks, I’ll look at that. A bit of an update as I realise I’m mistaken about it not reporting to HA. I manually changed the temperature setting on the thermostat using the SmartLife app and it updated in HA. For info, this is what the states are in developer tools. As you can see, HA can’t read the current temperature and I can’t control it from HA.

hvac_modes: off, heat_cool
min_temp: 1
max_temp: 7
target_temp_step: 0.5
current_temperature: null
temperature: 2.3
friendly_name: Blah thermostat
supported_features: 1

1 Like

Sorry to come back so quickly. I installed the old Tuya using HACS, deleted the new Tuya, restarted HA but I can’t see how to configure my devices in the old Tuya. There’s nothing I can see to set it up.

Refresh your browser ( Ctrl + F5 )

ScreenShot_20211114161050

Groan! I tried just about everything except refreshing the browser! Thanks so much for your help, it’s now working perfectly as it used to.

As we’re on the subject, can I be cheeky and ask for some more help! :grin: Ideally I’d like to use local control for my Tuya devices. I’ve had no success getting the local keys of my devices. I’ve tried the Tuya development platform but get a “code”: 1106, “msg”: “permission deny” error when I try to get the device information. I’ve tried packet sniffing using Packet Capture but I can’t create a certificate (seems to be a common problem these days).

I’m stumped. Would you have any suggestions for how I might get around this?

  1. Tuya 1106, permission deny
    https://support.tuya.com/en/help/_detail/K9kui9wvuwc93

  2. You Tube
    HOW TO - Get All Local Tuya Keys

    https://youtu.be/YKvGYXw-_cE

  3. https://iot.tuya.com

1 Like

Well it’s another laugh out loud moment! Your image 3 doesn’t look like what I see. Tonight, when I tried it I finally got an option that got me the local key! I swear I have tried every option without success, several times. The option that has worked for me, “Get Device Information”, seems new. The option “Get the device information” which, from its name, obviously does something completely different still gives the permission deny error!

Anyway, hopefully to help others here’s how it looks for me, and thanks again for your time, I do appreciate it.

1 Like

The math I figured out to get the correct temperature set point from my Della 12000 BTU Mini-Split was the following in Developer Tools > Templates:

{{ (((state_attr(‘climate.shed_mini_split’, ‘temperature’) - 142.0) / 1.777 + 61.0) * 2.0) | round(0) | float / 2.0 }}

However, I could not figure out how to override how this was appearing via the “Customize Entities” UI, and I couldn’t use the tuya-hacks download because the climate.py file only had a variable for TUYA_TEMPERATURE_MULTIPLIER which wouldn’t work because my math needs to subtract a constant before multiplying (or dividing in my example) by a constant then adding back a third constant. The custom_components/tuya hack only seems to allow for a constant multiplier and not for subtractive and additive constants?!?

Hello I’ve been trying for days to figure out why to resolve the issue with my Tuya devices showing the incorrect temperature. no mater what I’ve tried i cant seem to get the current temperature to display in HA. I see many posts about going into “configurations, integrations, tuya then options” and adjust the divider however this setting does not exist anywhere. I also tried to download and install the custom integrations such as GitHub - ollo69/ha_tuya_custom: Tuya Custom Component for testing however, when i install or place the folder into my “custom_components” folder the integration completely disappears from HA. i also tried local tuya and im able to add the device successfully however, im not able to get the correct temperature. any assistants anyone can provide is greatly apricated!

The new Tuya integration has no ability to adjust the multiplier and local Tuya doesn’t yet support thermostats. You have to revert to old Tuya. Follow the instructions above (basically: remove new Tuya, install old Tuya using HACS, restart HA, refresh your browser, set up old Tuya integration where you’ll then find the options for multipliers). Good luck!

1 Like

thanks so much for your response! their are so many links on this post. are you able to provide the link to the repository for “old tuya” so that i can download and install in my HA environment?

Like 3v1n0 i made a dirty hacks to tuya v2 component from its master branch and now it using hard-coded multiplier 2 and temp_step 0.5.
Get https://gazizova.net/pub/install/hassio/tuya.zip , check with antivirus (e.g. clamscan, don’t trust any guy from internet!), extract it to /config/custom_components/ and restart HA to try. If something wrong, remove this folder tuya.
Modified component is usable if you have one or several tuya climate devices only with one multiplier value (2 or 10). If you have several tuya devices with mixed values then use old tuya v1 component that have per-device settings.

2 Likes