Creating mqtt sensor

Hi all,
New to the mqtt stuff and tried to create a sensor for my water meter.
I’ve got rtl_433 and SDR up and running. I can see the events in mqtt explorer but for the life of me, I can not create a working sensor that updates. Any pointers in the right direction would be very helpful.
MQTT Explorer:

configuration.yaml for mqtt:

mqtt: !include mqttdevices.yaml

mqttdevices.yaml:

sensor:
 - name: "Manual Water Meter"
   state_topic: "rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202/consumption"
   #value_template: "{{ value_jason.consumption | float / 100 * 7.48 | round }}"
   device_class: water
   unique_id: 1549362202
   state_class: total_increasing
   unit_of_measurement: gal
   availability:
    - topic: "rtl_433/9b13b3f4-rtl433/devices/Neptune-R900/1549362202"

 - name: "Test WM"
   device_class: water
   unit_of_measurement: gal
   state_topic: "rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202/consumption"
   json_attributes_topic: "rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202"
   value_template: '{{ value_json.consumption }}'
   state_class: total_increasing

*NOTE: I’ve also tried with removing /consumption.

and what I get (no state, no data):


sensor:
  - name: "Manual Water Meter"
    state_topic: "rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202/consumption"
    value_template: "{{ value | float(0) / 100 * 7.48 | round(0) }}"
    device_class: water
    unique_id: 1549362202
    state_class: total_increasing
    unit_of_measurement: gal
    availability:
      - topic: "rtl_433/9b13b3f4-rtl433-next/availability"

The payload of the following topic contains a number value.

rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202/consumption

It’s not a JSON dictionary so you can’t use value_json to reference the number value (you simply use value).

In addition, this topic contains sub-topics, not a JSON dictionary as its payload.

rtl_433/9b13b3f4-rtl433-next/devices/Neptune-R900/1549362202

Therefore you cannot use it for json_attributes_topic.

The availability topic expects (by default) its payload to be online/offline. The topic you used didn’t fulfill that requirement. That’s why I changed it to:

rtl_433/9b13b3f4-rtl433-next/availability

It’s the only existing topic whose payload is online/offline.

1 Like

Thank you so much for the assistance!

1 Like