BHT-6000 Thermostat (tuya) support

Discontinued - The Following method is not updated and doesn’t work with recent version of Home Assistant. Suggestion for that device is to move to a different thermostat firmware GitHub - klausahrenberg/WThermostatBeca: Replaces original Tuya firmware on Beca thermostat with ESP8266 wifi module and use that via mqtt (as discussed in this thread). All mentioned below has to be intended as a start-point for who wants to continue developing-maintaining this

Modified tuya doesn’t work anymore but a local interface is provided (It works but must be intended for Testing Purpose Only, without any warrantly or responsability)
I have configured that Thermostat (BHT-6000) following that steps:

  • Registered the device in “TuyaSmart” app instead of the “My Smart Thermostat” app (the one of the instruction qr code)
  • Added tuya support in home assistant:
tuya:
  username: YOUR_TUYA_USERNAME
  password: YOUR_TUYA_PASSWORD
  country_code: YOUR_ACCOUNT_COUNTRYCODE

Notes and Issues:

workaround to show what the unit is doing is by adding a binary sensor - platform: template like this:

binary_sensor:  
   - platform: template
     sensors:
        - termostato:
              friendly_name: "Stato Termostato Camera"
              value_template: "{{ (state_attr('climate.<climate_id>','current_temperature')) < (state_attr('<climate_id>','temperature')) }}

Bigger problem (for me):


UPDATE 1 – No Longer working

Modified tuya.py to get correct temperature (not doubled) and full google home integration (voice and dashboard)
That’s a rough workaround for testing purpouse, not a stable solution
Only work when thermostat is in manual mode:

  • rename the attached ‘tuya.yaml’ in ‘tuya.py’ (can’t apload .py as github attachment)
  • create a folder named ‘climate’ in ‘custom_components’ folder
  • copy tuya.py in previous ‘climate’ folder
    tuya.yaml (5.6 KB)

Notes on modified tuya.py:

  • Temperature formula correction:

    @property
    def current_temperature(self):
    """Return the current temperature."""
       full = round((float(self.tuya.current_temperature())/ float(2)),2)
       return full
    
  • Google Home Workaround details:

    @property
    def current_operation(self):
    """Return current operation ie. heat, cool, idle."""
        #mode = self.tuya.current_operation()
        #if mode is None:
            #return None #TUYA_STATE_TO_HA.get("idle")
        #return TUYA_STATE_TO_HA.get(mode)
        if self.current_temperature < self.target_temperature:
           return TUYA_STATE_TO_HA.get('hot')
       else:
           return TUYA_STATE_TO_HA.get('off')
    
  • Operation Mode are disabled (actually working on this)

    def set_operation_mode(self, operation_mode):
      """Set new target operation mode."""
      return
      self.tuya.set_operation_mode(HA_STATE_TO_TUYA.get(operation_mode)) 
    
  • In Google home correction, if the target temperature is < room temperature the device is reported off without the ability to set temperature (there is no ‘idle’ feature on google home trait schema)
    to get target temperature also when idle (but loosing the ability to see if the device is on or off), change this:
    return TUYA_STATE_TO_HA.get('off')
    to this:
    return TUYA_STATE_TO_HA.get('hot')

Know issues of that tuya.py:

  • Can’t get float value for current temperature value
  • Operation Mode disabled (set them does nothing)

Reference post: Smart Life (tuya) show wrong temperature

That mod overrides Official Tuya Climate Support, it’s not applicable if there are other Tuya Climate Dev
To Revert Back to Official Tuya Support Remove that tuya.py from /custom_components/climate/

  • After any change to python files an hass restart is needed
  • That Mod is for testing purpouse and not for stable use, in future a separate components must be made

LAN Control
The device can be controlled locally, refer to GitHub - TuyaAPI/cli: 🔧 A CLI for Tuya devices and tuyapi/docs/SETUP.md at master · codetheweb/tuyapi · GitHub for full steps

The device has the following dps:
1 - Device Screen: “false” off - “true” on
2 - Doubled set temperature ( 40 is 20°)
3 - Doubled ambient temperature
4 - Work Mode - 0 auto - 1 manual
5 - Unknown - Actual value “false”
6 - Unknown - Actual value “false”
102 - Unknown - Actual value “0”
103 - Unknown - Actual value “1”
104 - Unknown - Actual value “true”

That custom_component provides local readings, with some limit (polling less than 30 sec causes instability)
localtuya.yaml (9.1 KB)

– Updated version for hass 89.1 climate.yaml (9.0 KB) → rename to climate.py and follow :

It’s for testing purpouse, it works but needs more tests

  • Copy the file in custom_components/climate and then rename from localtuya.yaml to localtuya.py

  • Add that to configuration.yaml

     climate:
        - platform: localtuya
          host: deviceIp
          local_key: 'localKey'
          device_id: 'deviceId'
          name: 'name'
          scan_interval: 20
    
  • It works with google home integration (just expose)

  • Away Mode is the Eco Mode → Echo mode can be turned on both via “Eco” and “Away” but can be deactivated only with away mode

Other Things

As seems, manufacturer is not interested on correct the way the target temperature is reported when in automatic mode.
So meanwhile i’m exploring GitHub - xoseperez/espurna: Home automation firmware for ESP8266-based devices for a custom firmware

Known issues of the device:
If the device is in schedule mode, the app, and also the local reading does not report correctly the temperature set


UPDATE 2 - Deprecated
Side Notes:

changing in localtuya.py, from

def status(self):
    """Get state of Tuya switch and cache the results."""
    self._lock.acquire()
    try:
        now = time()
        _LOGGER.debug("UPDATING status")
        if not self._cached_status or now - self._cached_status_time > 30:
          self._cached_status = self.__get_status()
          self._cached_status_time = time()
          return self._cached_status
    finally:
        self._lock.release()

to:

def status(self):
    """Get state of Tuya switch and cache the results."""
    self._lock.acquire()
    try:
        now = time()
        _LOGGER.debug("UPDATING status")
        #if not self._cached_status or now - self._cached_status_time > 30:
        self._cached_status = self.__get_status()
        self._cached_status_time = time()
        return self._cached_status
    finally:
        self._lock.release()

allows to set a lower scan_interval: now i’m at 5 sec and there’s no issues till now


UPDATE 3:
with scan interval at 5 device does not responds to commands (set_temperature, mode, etc),
If this happen increase to 10
(rapid readings makes set to be rejected, as the readings are issued by command)


UPDATE 4:

climate:
  - platform: localtuya
    host: deviceIp
    local_key: 'localKey'
    device_id: 'deviceId'
    name: 'name'
    scan_interval: 5
    min_temp: 5
    max_temp: 35

Allows to get full temperature range (by default is 7-21 degree) in combination with this new localtuya.py file localtuya.yaml (8.9 KB) → See above for updated file
The code was also modified to try to resolve the 5 second update interval. At this time it seems to work, but more tests are needed (didn’t know exactly how python lock works)


Remember that using the official app (tuya, ecc…) will cause connection rejection to local readings, so there are’t update unless the app is open

ANY HELP IS APRECIATED

3 Likes

Hello,
where you put this config:

termostato:
 friendly_name: "Stato Termostato Camera"
 value_template: "{{ (state_attr('climate.<climate_id>','current_temperature')) < (state_attr('<climate_id>','temperature')) }}
binary_sensor:  
   - platform: template
     sensors:
         termostato:
              friendly_name: "Stato Termostato Camera"
              value_template: "{{ (state_attr('climate.<climate_id>','current_temperature')) < (state_attr('<climate_id>','temperature')) }}

that’s a workaround, assuming that if set temperature is bigger than actual temperature the device is on
updated first post

Ok, i made a change because the check config, displayed an error.

So this my code:

binary_sensor:  
   - platform: template
     sensors:
         termostato:
              friendly_name: "Stato Termostato Camera"
              value_template: "{{ (state_attr('climate.ID','current_temperature')) < (state_attr('climate.ID','temperature')) }}"

This work, but show always the state “on” , i’m using a Week Schedule, scheduled through the App.

I see that you are italian too :smiley:

Thanks!

1 Like

About the template:
Yes, there was an error in the “-” sign, sorry but I have a large configuration and is not easy to grab some snippet of code… :sweat_smile: Now corrected in previous post

That workaround did not get data from the thermostat, it works by the assumption that if the room temperature is lower than the temperature set, the device is on. I’m using the thermostat in manual mode so didn’t know how that assumption works in automatic mode.

Now, check the two temperature values in home assistant, if binary sensor reports “on” when actual_temperature is lower than set_temperature there’s an error in the template that needs more investigation, otherwise is something related to the automatic mode (maybe the set_temperature is always bigger and the trigger is made by the thermostat clock).
Try check entity states in the home assistant states tab (the “< >” button in the left menù) to see if another workaround is possible.

Mine is the following:

max_temp: 35
min_temp: 5
target_temp_step: 1
temperature: 16
current_temperature: 16
friendly_name: Camera
supported_features: 4097

Actually I’m trying to understand the supported_features value

About Google Home:

Talked to google home support about the tuya integration, voice commands works and I will receive some news about the dashboard. So if you say “set < device name > to 5 degree” the device sets to 5°
For google home integration i’ve added the devices as Tuya Smart instead of the suggested Smart Life, didn’t know why but i think that’s better…
< tra italiani :laughing: > Se al google home o all’assistant dico “imposta < nome termostato > a 20 gradi” lui lo fa, per comodità nell’app google home ho dato un nickname breve ai termostati per evitare di fare discorsi lunghi con l’assistant < /tra italiani>

For home assistant support i’ve opened an issue, probably the hass community can solve the issue in less time than tuya or google home developer. The idea is the following: disconnect the device (trough tuya) on google home and reconnect them as home assistant device with exposing the climate component to google assistant

1 Like

Another things:
I’ve seen that in automatic mode also the proprietary app does not show the set temperature. Example:

Temperature is set to 15°
Schedule sets temperature to 20° at certain time

Device display shows 20° but the app still display 15°

That’s why my workaround doesn’t work for you

updated first post

Where I put tuya.yaml?

updated first post

I have solved double temperature problem with your tuya.py but in Google home I cannot see temperature. Can you help me?

The themostat is in manual or automatic mode?
The target temperature is lower than room temperature or not?

Thermostat is in manual mode and temperature is lower of room

correction is already on first post.

@property
def current_operation(self):
“”“Return current operation ie. heat, cool, idle.”“”
#mode = self.tuya.current_operation()
#if mode is None:
#return None #TUYA_STATE_TO_HA.get(“idle”)
#return TUYA_STATE_TO_HA.get(mode)
if self.current_temperature < self.target_temperature:
return TUYA_STATE_TO_HA.get(‘hot’)
else:
return TUYA_STATE_TO_HA.get(‘off’)

In Google home correction, if the target temperature is < room temperature the device is reported off without the ability to set temperature (there is no ‘idle’ feature on google home trait schema)
to get target temperature also when idle (but loosing the ability to see if the device is on or off), change this:
return TUYA_STATE_TO_HA.get('off')
to this:
return TUYA_STATE_TO_HA.get('hot')

usually thermostat (like netatmo) handles ‘off’ like you get, I didn’t like that way, so changing the tuya.py code as above will enable temperature change. But lost the feature to see if heating is on or off.
Actually, google does not support ‘idle’ state (I’ve made a request to add that feature). So there are three way to handle off state:
off → the default in my code to reproduce other devices like netatmo
hot → ability to set temperature but always shows “heating”
cool → ability to set temperature, shows heating when heating on, shows cooling when heating off

ops! localtuya stop to work if I remove the thermostat from tuya app o.O

Didn’t tried this, probably without registration the device does not work locally. Anyway the device works also if not connected to internet (isolated via router)

Hi how can I have local key and device ID? Pheraps device ID I founded in raspberry in file core_entity_registry that I found on my raspberry on folder situated in /home/homeassistant/.homeassistant/.storage but how can I obtain local key? Can you help me please?

Follow the steps here:

I read and done the guide but I have errors every time I use raspbian with Home assistant.

Maybe because when you remove it from tuya app this send a command to the device and delete wifi setting

1 Like

what kind of error?