How to use Sonoff TH16R2 with generic thermostat

I’m having trouble with controlling the switch component of my TH16R2.

Home assistant is installed on a linux machine using HassIO - 2022.4.6

I have set up the generic thermostat as follows

  - platform: generic_thermostat
    name: Bedroom
    heater: switch.sonoff_10012a2bca
    target_sensor: sensor.sonoff_10012a2bca_temperature
    min_temp: 5
    max_temp: 25
    hot_tolerance: 0.5
    initial_hvac_mode: heat
    ac_mode: false

However, on the dashboard the thermostat is visible, shows the room temperature, shows the set temperature but has no effect on the switch at all - if the flame icon is on or not.

I also have an entity card on the dashboard showing the switch and the measured temperature but turning that switch on results immediately in the switch turning off - again, independant of the set temp on the thermostat.

This behaviour is strange to me. I have no automations set up but I presumed (maybe incorrectly) that the thermostat would operate the switch?


You should not have any automation defined for the switch. The thermostat is “the automation”.

I think you should focus on the switch as such to begin with, and make sure it works as expected. Temporarily remove the thermostat definition and make sure you can manually set it on and off.

If it works as expected also check the temperature sensor. Then continue with the thermostat again.

1 Like

So I removed the thermostat form the config.yaml file and surprise… the switch works as it should as does the temperature sensor. So now I’m confused because it seems that the generic thermostat integration is the issue. I guess there must be a problem with my code but I’m not seeing it…

Hm, sounds strange. I made a test on my own system and added a button to manually operate one switch coupled to a thermostat. The thermostat indicates switch is off, since the temperature is higher than the setpoint. When I push the button, the thermostat immediatly indicates the switch is on and does not change back. I waited some time to see if the thermostat reacts on the switch state, but it does not. So my conclusion is the thermostat only listens on sensor state changes which is logical.

So in your case it looks like the thermostat picks up a state change of the sensor for some reason and the reading is higher than the setpoint, and this results in switch off.

When I added my test button and pressed the button not only the associated thermostat was affected. One other thermostat also turned on. I had to change the setpoint on that thermostat to switch off that specific heater. This just happened on my very first use of my test button. So I’m afraid the thermostat integration is a bit shaky.

I’m not using the generic thermostat, but the simple thermostat. This is available in HACS. This is modfied version of the generic thermostat to enable full preset management. But it is based on the generic thermostat.

I must say I feel a bit uneasy about this. It seems like the thermostat integration is a bit shaky.

I’m afraid I’ve ended up with a similar problem, see my post: Strange thermostat behaviour - #3 by bengtner

In my case the switch turns on within a few minutes. My thermostat understands this is the wrong state and turns the switch off. And then it goes on again.

Still I haven’t figured out if it is HA that manipulates the switch beside what comes from the thermostat. I was wrong in my statement the thermostat does not monitor the state of the switch. It does. So if you manually change the switch status, the thermostat will discover this and restore the previous state if needed. But it takes some time before this happens.

I have 6 thermostats in my system and one of them behaves like this. In this case it is a Zigbee switch over MQTT that jumps on and off. All other (stable) switches are implemented by GPIO over MQTT.

Thanks for the input So I got mine to work but only by using another switch i.e not the Sonoff one. Now the issue is that the generic thermostat defaults to the target temp set in the config on homeassitant restart - which is obviously not ideal.
Need to find a setting to get it to default to last setting…

OK, take a look at the simple thermostat, Simple thermostat with preset modes management . It’s a derivate of the generic thermostat. It supports true preset mode management. As long as you use a preset mode, it preserves settings at restart. But it does not work well with preset ‘none’. Then you must a target value in the config that kícks in at restart.

Hm, I have Sonoff switch as well, 01MINIZB,…