MQTT sensor with special chars ("[")?

Hi,

I am trying to add a MQTT based sensor through configuration file as follows:

   -sensor:
        - state_topic: hzg/status
          name: "ow_t_out"
          unique_id: hzgowtout.mqtt
          unit_of_measurement: "°C"
          device_class: "temperature"
          force_update: true
          value_template: '{{value_json.onewire.t_out[0]}}'

When using MQTT explorer the message in MQTT looks like this (sorry only screenshot):
grafik

When checking on the dashboard the sensor says “Unknown”.

I somehow guess it is because of the brackets (‘[’ and ‘]’), am I right?

How can I enter the sensor in the .yaml file so it gets recognized properly?

Thanks!

/KNEBB

Try this version of the template.

          value_template: '{{ value_json.onewire["t_out[0]"] }}'

Your version leads the Jinja2 processor to think that t_out is a list and it should get the zeroth item from the list.

Hello

It’s JSON, so you need to escape things with a .

Examples from one of my blueprints…

Tried these:

.["t_out[0]"]
.t_out\[0\]

None of them did work.

This seems to be working now:
value_template: '{{value_json.onewire["t_out[0]"] }}'
Mind the missing “.” before the first bracket and after “onewire”.

Thanks @123

/KNEBB

1 Like