MQTT Json Sensor not working

Hello guys,

I have a problem with creating a sensor out of my Seplos Battery MQTT message:

I updated my configuration.yaml with:

# Seplos Batterie 1 RS485
  - platform: mqtt
    name: "seplos1_battery_remaincapacity"
    state_topic: "Seplos/Seplos_52c0a1/AllJsonData"
    unit_of_measurement: "Ah"
    value_template: "{{ value_json.RemainCapacity }}"
  - platform: mqtt
    name: "seplos1_battery_voltage_diff"
    state_topic: "Seplos/Seplos_52c0a1/AllJsonData"
    unit_of_measurement: "V"
    value_template: "{{ value_json.value.CellDiffMv }}"
  - platform: mqtt
    name: "seplos1_battery_cycles"
    state_topic: "Seplos/Seplos_52c0a1/AllJsonData"
    unit_of_measurement: ""
    value_template: "{{ value_json.value.BatteryCycles }}"

I tried a lot of configurations but could not get it running, i also read a few other threads and also the help file, but already wasted some hours.
Could anybody help me out?
Thanks, best regards,
Dominik

  1. Is an MQTT broker installed and is functional?
  2. Is the MQTT integration installed and is functional?
  3. Are the three MQTT Sensors defined under the sensor: key in configuration.yaml?
  4. Did you either execute Reload Manually Configured MQTT Entities or restart Home Assistant?
  5. Are there relevant error messages in the Log?

1.yes see first screen shot. Mqtt messages are published on the configured topic
2.yes many other sensors already work for a long time
3. Yes see the posted cutout of my config it is under sensor.
4. Restarted HA many times
5. No errors in this mosquitto broker log.

I understand that Topics are case sensitive. Try Seplos/SEPLOS_52c0a1/AllJsonData.

2 Likes

Bingo!

From MQTT Essentials:

@123 @wmaker You guys are the best, thank you very much for solving the issue and helping me out of my stupidness! Awesome

Great! If you would, mark this as the solution.

Hello,

I have a somehow similar problem. My ESP8266 Arduino sends MQTT topics to Mosquito Broker. And it is successfully received in HA. Below is the extract from MQTT Settings page:

Listen to a topic
 
Listening to
vrane/meteo1/env
 
Message 0 received on vrane/meteo1/env at 21:04:
{
    "data": {
        "Temp": 23.75,
        "humid": 51.02929688,
        "press": 993.3134155,
        "batt": 1.771000028
    }
}
QoS: 0 - Retain: false

So ESP8266 sends topics, MQTT is properly configured and receives topics.

I have configured sensors in the configuration.yaml as follows:

mqtt:
  sensor:
    - name: 'Meteo_Temperature'
      state_topic: 'vrane/meteo1/env'
      unit_of_measurement: '°C'
      value_template: '{{ value_json.Temp }}'
    - name: "Meteo_Humidity"
      state_topic: "vrane/meteo1/env"
      unit_of_measurement: "%"
      value_template: "{{ value_json.humid }}"        
    - name: "Meteo_Pressure"
      state_topic: "vrane/meteo1/env"
      unit_of_measurement: "hPa"
      value_template: "{{ value_json.press }}"    
    - name: "Meteo_Battery"
      state_topic: "vrane/meteo1/env"
      unit_of_measurement: "V"
      value_template: "{{ value_json.batt }}"    

But I am not able to get rid of this error from Logs. I probably do some silly mistakes, but I cannot solve them.

Logger: homeassistant.helpers.template
Source: helpers/template.py:582
First occurred: 20:55:14 (428 occurrences)
Last logged: 21:09:23

Template variable warning: 'dict object' has no attribute 'Temp' when rendering '{{ value_json.Temp }}'
Template variable warning: 'dict object' has no attribute 'humid' when rendering '{{ value_json.humid }}'
Template variable warning: 'dict object' has no attribute 'press' when rendering '{{ value_json.press }}'
Template variable warning: 'dict object' has no attribute 'batt' when rendering '{{ value_json.batt }}'

Other MQTT sensors (Tasmota) already work for a long time
I have restarted HA many times
No errors in this Mosquitto broker log.

Can you please advise?

Thank you, Leon

Those warning messages will appear if the received payload doesn’t look like the example you posted. In other words, if the payload isn’t a dictionary containing a Temp key then this template {{ value_json.Temp }} will fail.

Try this version:

      value_template: '{{ value_json.Temp if value_json.Temp is defined else this.state }}'

@123 Thank you. I will try.
Nevertheless, the example is taken directly from MQTT Mosquitto, from the menu “Listen to topic” and this is exactly what is received inside HA. If I understand well this version will avoid the error in the log, but will not read the value from MQTT message.

 value_template: '{{ value_json.Temp if value_json.Temp is defined else this.state }}'

Now that I look more closely at what you posted I realize I failed to pay close attention to the payload’s format. :man_facepalming:

Change this:

      value_template: '{{ value_json.Temp }}'

to this:

      value_template: '{{ value_json.data.Temp }}'
1 Like

Hello @123 ,

🤦🤦🤦This is it!
THANK YOU!!!

1 Like

Hi, I have a Seplos BMS how did you get the messages into MQTT?