MQTT Trouble Adding Sensor

EDIT: Solved. Code updated to comment out availability section.

Hi all, this is my first time trying to add a custom mqtt sensor to HA through the configuration.yaml

I have setup a raspberry pi pico w to publish messages via mqtt. I can see these messages when using the MQTT listen to a topic functionality. Also can see the data coming through as a subscribed topic under the device created.

Only issue is that my sensor is not updating.

mqtt:
  sensor:
    - name: "Total Usage"
      object_id: "total_usage"
      state_topic: "rpicow/frontgarden/mainwatermeter"
      #availability:
      #  - topic: "rpicow/frontgarden/mainwatermeter"
      device_class: "water"
      state_class: "total_increasing"
      icon: "mdi:water"
      unit_of_measurement: "L"
      value_template: "{{ value | float | multiply(5) }}"
      unique_id: "total_usage"
      device:
        name: "Main Water Meter"
        identifiers: "raspberry_pi_pico_w"
        manufacturer: "Raspberry Pi"
        model: "Pico W"

I have shared some screenshots of my code, and the data coming through.

HI
Indentation of the yaml lines is very important. You are more likely to get a response if you show it like in example below. You could just be making a simple mistake in how you are indenting your code.

# Example configuration.yaml entry
mqtt:
  sensor:
    - name: "RSSI"
      state_topic: "home/sensor1/infojson"
      unit_of_measurement: "dBm"
      value_template: "{{ value_json.RSSI }}"
      availability:
        - topic: "home/sensor1/status"
      payload_available: "online"
      payload_not_available: "offline"
      json_attributes_topic: "home/sensor1/attributes"

Hi Spiro,

Thanks for the advice. I wasn’t sure how to put the code in, but a quick google search helped. I have now done so now.

Did you go into developer tools and select reload manually configured mqtt entities?

Also better to use mqttexplorer to look at mqtt data. Easier to see whole topic

Hi Spiro,

I think I figured it out. I basically commented out most lines of code, and began with a basic sensor, then slowly removed the # from each line.

The issue seems to be coming from the availability topic, where I am using the same path as the state topic. It doesn’t seem to like that for checking availability.

At the moment I have got it working with a very basic payload of just one parameter. Later on I will look to add more parameters being sent such as battery level and so forth.

Glad you got it sorted. :+1:

Appreciate you jumping in to help me out. Thank you :slight_smile:

Hi, welcome to the forum and good you got it solved!

Please take the time to mark the solution as the answer, you do that by selecting the three dots under the post:

image

Then select the check box:

image
By doing so this can be useful to other users as well (this thread comes up as solution when staring a related thread).