MQTT value_template for watermeter

I just built me a image recognition watermeter reader following this cool project:
I even got the mosquito add-onn and mqtt Integration to work. When listening, I get this message:

Nachricht 16 empfangen auf wasserzaehler/main/json um 20:26:
    "value": 304.7439,
    "error": "no error",
    "rate": 0,
    "timestamp": "2021-11-20T20:25:16"

So I tried to configure a sensor like this:

-platform: mqtt
  name: "Wasserzaehler"
  state_topic: "/wasserzaehler/main/json"
  value_template: "{{ json.value }}"
  unit_of_measurement: "m3"
  icon: "mdi:water"

I also tried value_json.value istead of json.value
But I only get to see “unknown” as sensor state.

I’m completely “virgin” to MQTT, so probably I’m just too dumb to set the Template correctly, but I simply can’t figure, how :frowning:

Thank’s for any helpful thoughts!

1 Like


- platform: mqtt
  name: "Wasserzaehler"
  state_topic: "wasserzaehler/main/json"
  value_template: "{{ value_json.value }}"
  unit_of_measurement: "m3"
  icon: "mdi:water"

I did, unfortunately without success.

Try removing the leading /, I’ve edited my post

That did it! You made my day!

hello, hello @fedot,

i just got into this meter. esp is up and running. but it looks like i am not recieving any mqtt data. just to clearify. you are sending this to the broker addon. right?

I’ve never used this setup, I just saw the problem.
You can use the addon, yes, make sure it’s set up properly and you can connect to it using sth. like MQTT explorer.
Use the IP of your Home Assistant instance on your ESP.
If that doesn’t work, post your config file on the ESP so we can troubleshoot.

In New Version that not puplished yet is it possible that HA find the AI via auto discover on mqtt. Like that project also

made it work. double checked with mqtt explorer. your reply was good to know that i was on the right way! thanks