Multiple DS18B20 - Tasmota - MQTT

Hi,
I have multiple DS18B20 connected to a Wemos D mini running Tasmota.
I see 3 diferend temperature valus in Tasmota.
Console showing:
15:10:40 MQT: tele/tmp/SENSOR = {“Time”:“2018-12-04T15:10:40”,“DS18B20-1”:{“Id”:“020491771E52”,“Temperature”:19.8},“DS18B20-2”:{“Id”:“021091776542”,“Temperature”:19.3},“DS18B20-3”:{“Id”:“021491776797”,“Temperature”:18.9},“TempUnit”:“C”}

But i am not able to get 3 difirerend valus in Home Assistant.
For 1 sensor it works fine.
sensor:

  • platform: mqtt
    name: “tmp1”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20.Temperature }}”
  • platform: mqtt
    name: “tmp2”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20.Temperature }}”
  • platform: mqtt
    name: “tmp3”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20.Temperature }}”

I put the following into the Template editor and it seems to work:

{% set try_this = {
  "Time":"2018-12-04T15:10:40",
   "DS18B20-1":{"Id":"020491771E52","Temperature":19.8},
   "DS18B20-2":{"Id":"021091776542","Temperature":19.3},
   "DS18B20-3":{"Id":"021491776797","Temperature":18.9},
   "TempUnit":"C"
   }
%}

Sensor 1 temperature is {{ try_this["DS18B20-1"].Temperature }} {{ try_this.TempUnit }}.
Sensor 2 temperature is {{ try_this["DS18B20-2"].Temperature }} {{ try_this.TempUnit }}.
Sensor 3 temperature is {{ try_this["DS18B20-3"].Temperature }} {{ try_this.TempUnit }}.
1 Like

You are trying to read ‘DS18B20’ three times in home-assistant. The JSON output you posted in the first half of the post clearly lists ‘DS18B20-1’, ‘DS18B20-2’ and ‘DS18B20-3’.

My guess is you should change the value_template of each of your sensors accordingly.

Thanks for replly!
I have don a lot of chanches, but noting works.
Now i use:
sensor:

  • platform: mqtt
    name: “tmp1”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20-1.Temperature }}”
  • platform: mqtt
    name: “tmp2”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20-2.Temperature }}”
  • platform: mqtt
    name: “tmp3”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.DS18B20-3.Temperature }}”

And this is the error i see at info:

Error parsing value: ‘dict object’ has no attribute ‘DS18B20’ (value: {“Time”:“2018-12-04T16:10:25”,“DS18B20-1”:{“Id”:“020491771E52”,“Temperature”:20.1},“DS18B20-2”:{“Id”:“021091776542”,“Temperature”:19.8},“DS18B20-3”:{“Id”:“021491776797”,“Temperature”:19.1},“TempUnit”:“C”}, template: {{ value_json.DS18B20-1.Temperature }})

and

Error parsing value: ‘dict object’ has no attribute ‘DS18B20’ (value: {“Time”:“2018-12-04T16:10:25”,“DS18B20-1”:{“Id”:“020491771E52”,“Temperature”:20.1},“DS18B20-2”:{“Id”:“021091776542”,“Temperature”:19.8},“DS18B20-3”:{“Id”:“021491776797”,“Temperature”:19.1},“TempUnit”:“C”}, template: {{ value_json.DS18B20-2.Temperature }})

and
Error parsing value: ‘dict object’ has no attribute ‘DS18B20’ (value: {“Time”:“2018-12-04T16:10:25”,“DS18B20-1”:{“Id”:“020491771E52”,“Temperature”:20.1},“DS18B20-2”:{“Id”:“021091776542”,“Temperature”:19.8},“DS18B20-3”:{“Id”:“021491776797”,“Temperature”:19.1},“TempUnit”:“C”}, template: {{ value_json.DS18B20-3.Temperature }})

The - in the key will confuse the parser. You need to use the syntax suggested by @wmaker to put that key in quotes.

1 Like

Thanks for the reply’s

I have done some testing with.

  • platform: mqtt
    name: “tmp1”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json.[‘DS18B20-1’].Temperature }}”
    and
    value_template: “{{ value_json.[“DS18B20-1”].Temperature }}”
    and
    value_template: “{{ value_json.[DS18B20-1].Temperature }}”
    But it will not work for now.

remove the “.” after value_jason

1 Like

I am very happy!, After 2 week It works!
Thanks to @wmaker and @gpbenton

My code in Home Assistant:
sensor:

  • platform: mqtt
    name: “tmp1”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json[‘DS18B20-1’].Temperature }}”
  • platform: mqtt
    name: “tmp2”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json[‘DS18B20-2’].Temperature }}”
  • platform: mqtt
    name: “tmp3”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: “{{ value_json[‘DS18B20-3’].Temperature }}”

Wemos

6 Likes

I have tried the settings listed however I can not get anything to show. Am I missing something ?

06:56:35 MQT: tele/Anodize/SENSOR = {“Time”:“2019-01-17T06:56:35”,“DS18B20-1”:{“Id”:“02131DDB95AA”,“Temperature”:70.9},“DS18B20-2”:{“Id”:“02131DEE48AA”,“Temperature”:70.7},“DS18B20-3”:{“Id”:“02131DF42BAA”,“Temperature”:71.4},“TempUnit”:“F”}

  • platform: mqtt
    state_topic: “tele/Anodize/SENSOR”
    name: “Work Test 1”
    unit_of_measurement: “°F”
    value_template: “{{ value_jsonDS18B20-1.Temperature }}”

  • platform: mqtt
    name: “tmp1”
    state_topic: “tele/Anodize/SENSOR”
    unit_of_measurement: “°F”
    value_template: “{{ value_json[‘DS18B20-1’].Temperature }}”

  • platform: mqtt
    name: “tmp2”
    state_topic: “tele/Anodize/SENSOR”
    unit_of_measurement: “°F”
    value_template: “{{ value_json[‘DS18B20-2’].Temperature }}”

  • platform: mqtt
    name: “tmp3”
    state_topic: “tele/Anodize/SENSOR”
    unit_of_measurement: “°F”
    value_template: “{{ value_json[‘DS18B20-3’].Temperature”

I get an error on the copied code.

Configuration invalidCHECK CONFIG

Invalid config for [sensor.mqtt]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 14) for dictionary value @ data[‘value_template’]. Got ‘{{ value_json[‘DS18B20-1’].Temperature }}’. (See ?, line ?). Please check the docs at XXXX://home-assistant.io/components/sensor.mqtt/ Invalid config for [sensor.mqtt]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 14) for dictionary value @ data[‘value_template’]. Got ‘{{ value_json[‘DS18B20-2’].Temperature }}’. (See ?, line ?). Please check the docs at XXXX://home-assistant.io/components/sensor.mqtt/ Invalid config for [sensor.mqtt]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 14) for dictionary value @ data[‘value_template’]. Got ‘{{ value_json[‘DS18B20-3’].Temperature’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.mqtt/

Someone Please Help

The double quotes you have around the line do not appear to be normal ascii characters. Replace them with straightforward " and you should be fine.

After update my Tasmota to 6.3.0.14, i have to use this:

  • platform: mqtt
    name: “Garage”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: ‘{{ value_json[“DS18x20”][“DS1”][“Temperature”] }}’
  • platform: mqtt
    name: “Buiten achtertuin”
    state_topic: “tele/tmp/SENSOR”
    unit_of_measurement: ‘°C’
    value_template: ‘{{ value_json[“DS18x20”][“DS2”][“Temperature”] }}’

For info, I opt to use:

value_template: "{{ value_json['DS18B20-1'].Temperature }}"

Yes, it is very fussy about the quotes - and rightly so! As mentioned, some of the above messages don’t contain ASCII quotes: they’ve been replaced by “open / close quotes”. These need to be proper double quotes. Also, in my example, because I’m quoting the sensor name as the list index, I have to use single quotes because the whole template is inside double quotes.

This all works fine for me, but I would like to index it on “Id” rather than on the “DS18B20-1” name which TASMOTA has assigned it. Does anyone know how I might do that?

The published string is:

th10_02/tele/SENSOR {"Time":"2019-03-10T20:56:07","DS18B20-1":{"Id":"01159038DEFF","Temperature":58.8},"DS18B20-2":{"Id":"011590B1DEFF","Temperature":57.6},"DS18B20-3":{"Id":"011590B342FF","Temperature":42.2},"DS18B20-4":{"Id":"0415A231A5FF","Temperature":49.1},"DS18B20-5":{"Id":"0415A28B86FF","Temperature":59.9},"TempUnit":"C"}

So, basically, I want to find the .Temperature of the "DS18B20-nnn" where the .Id equals "01159038DEFF".

Anyone got any suggestions how I might do that? I think there’s a for loop involved, but I’m not at that stage yet!

Thanks.

1 Like

did you ever find a solution for this??

Not really, but I’m starting to grasp the string handler better. I’ll update when I learn something!

I had the same question here is my result (not finaly ready):

Return value:
{%- set sID = "0415A231A5FF" -%}
{%- set values = {
"Time":"2019-03-10T20:56:07",
"DS18B20-1":{"Id":"01159038DEFF","Temperature":58.8},
"DS18B20-2":{"Id":"011590B1DEFF","Temperature":57.6},
"DS18B20-3":{"Id":"011590B342FF","Temperature":42.2},
"DS18B20-4":{"Id":"0415A231A5FF","Temperature":49.1},
"DS18B20-5":{"Id":"0415A28B86FF","Temperature":59.9},
"TempUnit":"C"
} -%}
{%- for tsensor in values  -%}
  {%- if values[tsensor].Id == sID -%} {{values[tsensor].Temperature}}
  {%- endif -%}
{%- endfor %}

Does that help?

An after some tests:

  value_template: >-
    {%- set sourceid = '0415A231A5FF' -%}
    {%- for tsensor in value_json  -%}
      {%- if value_json[tsensor].Id == sourceid -%} {{value_json[tsensor].Temperature}}
      {%- endif -%}
    {%- endfor %}

hello,
I wrote in the configuration.yaml:

 - platform: mqtt  
    state_topic: "sonoff/tele/SENSOR"
    name: "Temperature bas du chauffe-eau"
    unit_of_measurement: 'deg. C'
    value_template: “{{ value_json['DS18B20-1'].Temperature }}”

The value of the sensor is: “16.0” With semicolon !
So The graphe can’t be displayed !
How can I have a floating value and not a text value ?
Thanks for your help.
Thierry

Dear @vormsty
for me it seems that you used wrong quotes for the value template. Could you please try this?

  value_template: "{{ value_json['DS18B20-1'].Temperature }}"
  device_class: temperature

I personally do not have any issues using this formula. Perhaps you have to convert the value by using (not tested):

  value_template: "{{ (value_json['DS18B20-1'].Temperature | float) | round(2) }}"

Pretty sure that there is a limitation within Tasmota of only one of any particular sensor type per device?
I tried two ultrasonic sensors on one device using tasmota and only one ever output data. Tried sonoffs and wemos and both the same result.
PS: You can configure three different type sensors though…just not three the same.

Dear @wellsy
I cannot agree to your interpretation: For onewire attached DS18B20 sensors the current Sonoff Tasmota firmware can definitely handle more than one device. I have three DS18B20 attached (working!) on a Sonoff Basic using onwire. I know that you can compile the firmware using an older library which only supports one DS18B20, but this is not default… Surely other sensors can only be used in a single configuration. I also ran into difficulties using two MCP23008.
At the moment i test the ESPHOME firmware, and i am surprised about the functionality and the capabillities…

1 Like