Thermostat Trouble


Hoping someone can help me here.

I have a DHT22 sensor hooked up to a raspberry pi and pushing its temperature out to my MQTT Broker. The output is formatted to 3 decimal places e.g 22.5.

I have setup the sensor in home assistant with the following code

- platform: mqtt
  name: Bedroom Temperature
  state_topic: "homeassistant/sensors/DHT22/temperature"
  unit_of_measurement: 'C'

I also have a relay connected to the PI and setup as a switch in home assistant. The relay turns on and off by the home assistant switch publishing MQTT messages to the Pi to turn it on or off.

So far so good this all works, the temperature shows up in HA and I can turn the relay off using a switch on the front end of HA.

I have now setup a climate script as outlined by HA.

in my configuration.yaml I have added the following line

climate: !include climate.yaml

In climate.yaml I have setup the following code

- platform: generic_thermostat
    name: Bedroom Thermostat
    heater: switch.mqtt_relay
    target_sensor: sensor.bedroom_temperature
    min_temp: 22.9
    max_temp: 29
    target_temp: 24

When i restart home assistant i can see “climate.bedroom_thermostat” under developer tools → states

It shows the following states :

operation_mode: idle
current_temperature: null
max_temp: 29
friendly_name: Bedroom Thermostat
temperature: 24
min_temp: 22.9
unit_of_measurement: °C

Can anyone help my as to why current_temperature: null?

My relay isn’t triggering and I believe this is probably the reason why. I have a scout around the forums and no one else seems to have run into this. The one topic I did find with the same issue no one had replied to it.


A wild guess here: maybe you publish your temperature in MQTT as a string instead of a number?

Check for typos too. Copy-paste the device id of the sensor from the HASS dev-state panel.

Hi Kirichkov

This is my Python script

Can you explain to me how I output as a number rather than a string? Im still new to all of this and still learning. I know the difference between a string and a number and it looks like it is outputting as you say to a string. How do I make it a number instead?

import paho.mqtt.publish as publish
import time
import sys
import Adafruit_DHT

time.sleep(15) #Sleep to allow wireless to connect before starting MQTT

while True:

    humidity22, temp22 = Adafruit_DHT.read_retry(22, 4) #22 is the sensor type, 18 is the GPIO pin number (physical pin 12

    if temp22 is not None:
        temp22 = str(round(temp22,3))
        print temp22
        publish.single("homeassistant/sensors/DHT22/temperature", payload=temp22, retain=True, hostname="", auth = {'username': "xxx", 'password': "xxx"})

    if humidity22 is not None:
        humidity22 = str(round(humidity22,3))
        print humidity22
        publish.single("homeassistant/sensors/DHT22/humidity", payload=humidity22, retain=True, hostname="", auth = {'username': "xxx", 'password': "xxx"})

EDIT: you’re clearly converting it to string, that’s what str() does.

Yeah spotted that bit, what I don’t know how to do is output the format as a number instead…as I say I’m new to python so a little guidance would be greatly appreciated.

This is much better asked at Python-forum, not here. I’d remove the str() but I can’t guarantee this won’t break it.

I did remove that as a guess and it removed my decimal formatting to 3 places but im not too fussed about that.

The script still worked and output a number similar to - 25.456654

Home assistant still says “null” on the climate monitor though so its still not registering it.

Ok Ill ask at a python forum, I just assumed as this was home assistant related due to one of their components not picking up a value it would be best to ask here as to why. I thought someone may know python on here who could help rather than get one part of my answer from here and then post it again on another forum to get the other part. Seeing as home assistants scripting is done with python I assumed there would be some python savy users on here.

Thanks for you input with this Kirichkov, but if you dont know the answer to this part ill will wait and see if someone else on here knows the answer to this.

the only thing I see is the unit of measurement in your temperature sensor; try putting °C instead of C


Hi MrMep

I put °C in before but when i restart HA I get the following error. Im not sure if i need to enter the special character in another way rather than copy and pasting it as I have done into the code. Any ideas?

Yeah, there are two different characters for the degree symbol… Did you copy&paste it? try entering it directly…
See here too: Climate Generic Thermostat with MQTT Temperature sensor

Thanks for that link

I did the first part by removing the unit_of_measurement: “ºC” on my sensor. Although before I did that I did try typing it as you suggested by holding down Alt and typing 0176 or Alt+248 - Neither of these worked and HA still threw up a hissy fit when restarting it.

I’m struggling with the next part. He says he created a custom component by copying the existing thermostat component and altering the code slightly. I cant find where my components are located to copy the code from the original to make a custom one as per this users instructions. A page i found says the components are located in a folder called components in your homeassistant directory, I dont have a components folder in my HA root folder… :-/

Ok I found the Python for the component on the github page and created a custom component as per the link you provided MrMep

My thermostat isnt showing under developer states any more and has gone completely…

Anyone got any more ideas?

Hi, is the temperature sensor showing in developer tools -> states?

It is yes, its reporting to HA just fine.

But the climate is still showing Null.

Ive tried adjusting my Python script on the PI to output as a number by changing “str” to “int”. Ive even spoken with some developers at work who understand python a little but arent experts on it and say if i use “int” that will be outputing as a number rather than a string. So not sure if this is now a HA problem rather than a python coding problem.

Ok, I don’t see unit_of_measurement under friendly_name, so I’m still thinking the problem is there.
As for the python script, actually an MQTT payload is always a byte array, and the publish function takes a string as argument, and in any case the value is showing in HA, so I guess the problem is not there…
You’d really need to figure out the right unit of measurement in the sensor declaration.
Try copying and pasting this (I hope it doesn’t get translated here in the forum):

    unit_of_measurement: "°C"

and put it in the sensor declaration.


Copy and pasted it as you said, still getting that error upon restarting HA

If you can explain to me how you type the Degree symbol maybe I can give that a go? Ive tried doing the Holding Alt Key plus the number combination on the keypad to type the symbol but again I get the same error as above when restarting HA.

And you get this error only when you put the ° symbol?

Correct! If I just type in “C” its fine but as you say the climate probably isnt working because its not reporting in the way its wants it to be.

So I think the solution is going to be finding out why it wont accept the symbol…

Yeah, the little ° is the key, but frankly I have no idea why it throws that error…