Generic Thermostat not able to retrieve current temperature!

Hi

I encounter a little issue using the generic thermostat component. It’s unable to retrieve the temperature value of my MQTT sensor !! The sensor itself displays well in HA frontend with correct temperature but not in thermostat component ! I thought I needed to convert in float the temperature value but it doesn’t accept typecasting :frowning: Some suggestions ?

Thanks

- platform: generic_thermostat
  name: Appartement
  heater: switch.chaudiere
  target_sensor: "{{ sensor.salon_temp_temperature | float }}"
  min_temp: 15
  max_temp: 30
  ac_mode: false
  target_temp: 19
  cold_tolerance: 0.3
  hot_tolerance: 0.6
  min_cycle_duration:
    seconds: 30
  initial_operation_mode: "off"
  away_temp: 15

Capture%20d%E2%80%99%C3%A9cran%20de%202018-02-02%2008-27-03

Try

target_sensor: sensor.salon_temp_temperature

Sorry forgot to mention it but it’s what I tried first and it was not working and so that’s why I went looking at more complicated solutions for basic thing !!

The template will not work.

Enable debugging for the component and check the log

In fact I got a guess about the problem, it looks like sensor returns unit (C for Celsius) as part of the number string for temperature and so thermostat is confused by it !!

Unable to update from sensor: C is not a recognized temperature unit.
11:13 components/climate/generic_thermostat.py (ERROR)

Don’t know how to remove it from string ! I thought that Float conversion would do that no ?

No, the generic does not support template.
Then you have to make a template sensor with {{ sensor.salon_temp_temperature | float }}
And link the template sensor to the generic thermostat

Or fix the mqtt sensor so that the state is only numeric (remove the unit from the state)

hi @vincen

What is your config for the temperature sensor? Particularly, what unit of measurement are you using?
I set two sensors in order to deal with the state of the sensor not being initialized when HA starts (and makes the temp at 25 degrees). First sensor is the raw value taken from the MQTT.

- platform: mqtt  
  state_topic: 'home/xxx/temp'  
  name: 'Initial SN Temperature'  
  unit_of_measurement: '°C
- platform: template
  sensors:
    sn_temperature:
      friendly_name: sn_temperature
      value_template: >
        {% if is_state('sensor.initial_sn_temperature', 'unknown') %}
          25
        {% else %}
          {{ (states.sensor.initial_sn_temperature.state | float )| round(1) }}
        {% endif %}
      unit_of_measurement: '°C'

Thanks for clarification, will go this way if I find out the second option is not working !

To be sure I checked content of mqtt messages and my mqtt sensor returns only the numerical value (there is no letter or symbol in string sent to MQTT !). I guess the problem is in config of that sensor in HA but the issue is that it’s a device added by auto discover in HA :confused: not sure what I can do here to fix that problem in HA !

As indicated just above there is no specific configuration as it’s a mqtt sensor added in HA by the autodiscover of HA so I didn’t do any configuration for it :frowning:

Then I suggest manually adding the sensors (you could also disable the auto discover).

Are you using a split for configuration.yaml or you have it all in there?

Looks like the good way to do but I have that error in logs trying to do the template:

Could not render template Temperature ambiante: UndefinedError: ‘sensor’ is undefined

and here is what I added in cofig file:

- platform: template
  sensors:
    temperature_ambiante:
      friendly_name: "Temperature ambiante"
      value_template: "{{ sensor.salon_temp_temperature | float }}"

Nope I don’t want to go this way as I want to use the auto discover feature for ease of add/removal of interfaces in my system :wink:

Spitted for sure !

For template sensor this should work.

- platform: template
  sensors:
    temperature_ambiante:
      friendly_name: "Temperature ambiante"
      value_template: "{{ states.sensor.salon_temp_temperature.state | float }}"

Thanks a lot it resolved the issue you are right :wink: May you just tell me what’s the function of states. and .state ? as I saw then mentionned on website but without any explanations :frowning:

So I updated my generic_thermostat to use now my variable with temperature correctly formatted but now it complains it has no unit ??? What’s the f*ck ? :disappointed_relieved:

Unable to update from sensor: None is not a recognized temperature unit.
15:04 components/climate/generic_thermostat.py (ERROR)

My updated thermostat:

- platform: generic_thermostat
  name: Appartement
  heater: switch.chaudiere
  target_sensor: sensor.temperature_ambiante 
  min_temp: 15
  max_temp: 30
  ac_mode: false
  target_temp: 19
  cold_tolerance: 0.3
  hot_tolerance: 0.6
  min_cycle_duration:
    seconds: 30
  initial_operation_mode: "off"
  away_temp: 15

Try this for unit:

- platform: template
  sensors:
    temperature_ambiante:
      friendly_name: "Temperature ambiante"
      value_template: "{{ states.sensor.salon_temp_temperature.state | float }}"
      unit_of_measurement: "°C"
1 Like

@vincen

I think that it is more convenient to add MQTT components manually. Splitting the configuration into multiple files would be much easier after you get the hang of it.

Anyway, try (as climate doesn’t accept templating):

target_sensor: sensor.modified_temp

and then setup the target sensor (in configuration.yaml):

sensor modified_temp:
  - platform: template
    sensors:
      modified_temp:
        friendly_name: 'Thermostat Target Temp'
        value_template: '{{states.sensor.salon_temp_temperature.state | replace("C","") | float | round(1)}}'