Temperature Sensor DS18B20 with a Sonoff TH10 config error in HA YAML

Hello
I’ve Home Assistant 0.82.0 on hassio.

Temperature Sensor DS18B20 is connected to a Sonoff TH 10 with Tasmota 6.3.0
The Temp. Sensor is working fine with Tasmota. The Topic is: TH10
The console reading is:

11:16:59 MQT: tele/TH10/SENSOR = {“Time”:“2018-11-16T11:16:59”,“DS18B20”:{“Temperature”:20.6},“TempUnit”:“C”}

The Sonoff is discoverd by HA with setoption19
The TH 10 can be switched in HA OK.

The Sensor DS18B20 configuration in HA is:

  -  platform: mqtt
     name: TH10
     state_topic: "tele/TH10/SENSOR"
     value_template: "{{ value_json['DS18B20']['Temperature'] }}"
     unit_of_measurement: "°C"

The dev. error message is:

Testing configuration at /config Failed config switch.mqtt: - Invalid config for [switch.mqtt]: required key not provided @ data['command_topic']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/switch.mqtt/ - platform: mqtt name: TH10 state_topic: tele/TH10/SENSOR unit_of_measurement: °C value_template: {{ value_json['DS18B20']['Temperature'] }} Successful config (partial) switch.mqtt:

I’ve testet serveral solutions, found in this forum. No luck so fare

Thank’s in advance for your help.

You need to define a sensor, not a switch.

1 Like

@gpbenton

Hi, thanks for your answer.
Can you explain how and where to do that?

The snippet that you posted needs to be in a section of your yaml that is defining sensors. See

@gpbenton

Hi, thank you very much, this did the trick, the DS18B20 is in HA.
I’ve moved all of my sensors, into the same section.

Somewhere I wrote, it doesn’t matter, where to have switches and sensor configs in the YAML File. This is obviously not true.

When the YAML file is growing, the best would be to create a Sub-YAML, each for switches and sensors.

I still have one sensor (mystrom) that only shows up in the HA dev states. I’m going to open another thread for it.

This sensor thing in HA, has cost me a lot of time already.

Thank you again,
Best Regards

1 Like

There is a page in the documentation about splitting up your yaml file, which is very popular, although I just keep everything in one file.

1 Like

Hi all,
Apologies if this is something simple, I’m still getting to grips with Home Assistant.
I’m having trouble getting the same sensor setup to work. I’ve used Node Red debug to confirm the MQTT topics and data show (topic: “tele/SonoffTH/SENSOR”
payload: “{“Time”:“xxx”,“DS18B20”:{“Id”:“xxx”,“Temperature”:17.8},“TempUnit”:“C”}” and have replicated and changed the above to reflect my current naming convention, but am struggling to get it to show the Temp data in HA The Sensor is setup as below. I suspect I’m missing something daft, any corrections would be appreciated.

sensor:
  - platform: mqtt
    name: “Temp Sensor”
    state_topic: “tele/SonoffTH/SENSOR”
    value_template: "{{ value_json['DS18B20']['Temperature'] }}"

I figured this one out 2 different ways:

  1. The speech marks used in name and state_topic were the wrong double speech marks as they’re different from the ones in value_template + I changed the value_template to “{{ value_json.DS18B20.Temperature }}”
  2. Much easier. As this had Tasmota running, I simply ran “SetOption19 1” on the devices console and Home Assistant picked it up automatically with none of the messing around.
    Oh well, chalk it down to a learning experience :slight_smile: