Sensor value_template platform: mqtt unknown value

Hope someone can give me some help.

I use a RFLINK setup with espRFLinkMQTT to publish to my mqtt server. This setup is working and i got TEMP sensors setup that show my temp in Home Assistant.

Then i got a DKW2012 weather station that also publish to rflink/DKW2012-00c0 with a payload of get this from MQTT Explorer
{“TEMP”:27.6,“HUM”:23,“WINSP”:0.0,“WINGS”:0.0,“RAIN”:0.0,“WINDIR”:0014,“BAT”:“OK”}

and using the command
mosquitto_sub -h 192.168.xx.xx -t “rflink/DKW2012-00c0” -v
result is
rflink/DKW2012-00c0 {“TEMP”:28.0,“HUM”:23,“WINSP”:0.0,“WINGS”:0.0,“RAIN”:0.0,“WINDIR”:0000,“BAT”:“OK”}

I set up a sensor in configuration.yaml under sensor:

RFLINK

  • platform: mqtt
    name: “DKW Temp”
    unique_id: dkw_temp
    state_topic: “rflink/DKW2012-00c0”
    value_template: “{{ value_json[‘TEMP’] }}”
    device_class: temperature
    unit_of_measurement: “ºC”

i also try the following as value_template
value_template: “{{ value_json.TEMP }}”

value_template: “{{ value_json[‘TEMP’].value }}”

under my development tool template i tested the template with the following and then is show now problem

{% set value_json=
{“TEMP”:27.5,“HUM”:23,“WINSP”:0.0,“WINGS”:3.7,“RAIN”:3.9,“WINDIR”:0004,“BAT”:“OK”}%}

{{value_json[‘TEMP’]}}
{{value_json.HUM}}
{{value_json.WINSP}}
{{value_json.WINGS}}
{{value_json[‘RAIN’] }}
{{value_json.WINDIR}}
{{value_json.BAT}}

can anyone help me
Thanks
Henry

The correct templates for the given mqtt payloads are the following

{{value_json.TEMP}}
{{value_json.HUM}}
{{value_json.WINSP}}
{{value_json.WINGS}}
{{value_json.RAIN}}
{{value_json.WINDIR}}
{{value_json.BAT}}

Using these you have to make the mqtt sensors like below.

  - platform: mqtt
    state_topic: "rflink/DKW2012-00c0"
    name: 'DKW Temp'
    force_update: 'true'
    unit_of_measurement: '°C'
    value_template: "{{value_json.TEMP}}"
    scan_interval: '10'

Please try these and even afte this if you are not receiving any outputs, the problem might be that the sensor maybe not updating the values. This could occur if the update interval in the sensor is set to high. You should make sure that the topic rflink/DKW2012-00c0 has received an output by listening to it from the mqtt integration.

Thanks did try the sensor as suggested but no luck for me. My update on the mqtt topic is between 48 sec en 96 second.

Thanks

Did you listen to the topic in mqtt integration?

Yes sorry I did not say that, but here is the mqtt_dump.txt output for 120sec
rflink/DKW2012-00c0,{“TEMP”:28.5,“HUM”:21,“WINSP”:6.1,“WINGS”:8.6,“RAIN”:0.0,“WINDIR”:0012,“BAT”:“OK”}
rflink/DKW2012-00c0,{“TEMP”:28.6,“HUM”:21,“WINSP”:7.3,“WINGS”:9.8,“RAIN”:0.0,“WINDIR”:0010,“BAT”:“OK”}

please remove the value_json and see if the whole mqtt message is being updated as the sensor state. If it appears we can change be sure its the value json issue.

All you have to do for these topic is add | default. This is mentioned in the breaking changes for templates.

{{value_json.TEMP | default}}
{{value_json.HUM | default}}
{{value_json.WINSP | default}}
{{value_json.WINGS | default}}
{{value_json.RAIN | default}}
{{value_json.WINDIR | default}}
{{value_json.BAT | default}}
1 Like

The logs now give me this error

ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.TEMP | default}}'

OK now i do get something

image

This seems to be the issue with the value_json decode. Is their a way to debug for the problem ?

Any solution to this? I have the same problem.