Help mqtt sensor on sensor.yaml config

hi all, i have a syntax problem with my configuration. I would like to put all the sensors in the sensor.yaml file, now when I insert the mqtt sensor I get a configuration error, the string I put in sensor.yaml is this:

######MEROSS STAMPA 3D
  - platform: integration
    source: sensor.presa_stampante_3d_power
    name: Consumo_Presa_stampa_3d_Kwh
    method: trapezoidal
    unit_prefix: k
    round: 2
mqtt:
  sensor:
    - name: Pellet Serbatoio
      state_topic: "tele/tasmota_pellet/PERCENT"
      unit_of_measurement: "%"
      availability:
        - topic: "tele/tasmota_pellet/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

but when i insert in configuration.yaml

mqtt:
  sensor:
    - name: Pellet Serbatoio
      state_topic: "tele/tasmota_pellet/PERCENT"
      unit_of_measurement: "%"
      availability:
        - topic: "tele/tasmota_pellet/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

i don’t recive error.

I assume you have this in your configuration.yaml file:

sensor: !include sensor.yaml

Everything you put into sensor.yaml must be an integration that is normally configured under the sensor: key.

The MQTT Sensor integration doesn’t go under the sensor: key, it goes under the mqtt: key. That’s why you got an error. You can’t mix the two types together.

Leave the MQTT Sensor configuration in the configuration.yaml file. Or create this:

mqtt: !include mqtt.yaml

and put the MQTT Sensor configuration in the mqtt.yaml file like this:

  sensor:
    - name: Pellet Serbatoio
      state_topic: "tele/tasmota_pellet/PERCENT"
      unit_of_measurement: "%"
      availability:
        - topic: "tele/tasmota_pellet/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

i put the config in mqtt.yaml but i recive this

  sensor:
    - name: Pellet Serbatoio
      state_topic: "tele/tasmota_pellet/PERCENT"
      unit_of_measurement: "%"
      availability:
        - topic: "tele/tasmota_pellet/LWT"
      payload_available: "Online"
      payload_not_available: "Offline"

then i modify in

  sensor:
    - name: Pellet Serbatoio
      state_topic: "tele/tasmota_pellet/PERCENT"
      unit_of_measurement: "%"

i see the mqtt explorer and recived vailability topic

The problem with availability is unrelated to your original question. You had a syntax problem and I explained how to fix it. You followed my instructions and eliminated the syntax problem.

Availability is a separate issue. It was unavailable because of your choice of availability topic and payloads. You should check tele/tasmota_pellet/LWT and confirm its payload is actually Online because it appears that it isn’t and that’s why the sensor reported unavailable.

i know the availability is differnte problem, i write here for not create a lot post. this is mqtt explorer and LWT in online
image
and the topic
image

Have you tried this?

sensor:
    - name: Pellet Serbatoio
      state_topic: tele/tasmota_pellet/PERCENT
      unit_of_measurement: "%"
      availability_topic: tele/tasmota_pellet/LWT
      payload_available: Online
      payload_not_available: Offline

very nice now all done

1 Like

The example in the documentation (about half way down the page) shows quotes around all of the values.

For me, it doesn’t show available whether I have quotes or not.

What should I try next?

OSD

I suggest you start a new topic containing your sensor configuration that isn’t working.

Thanks, I figured it out. The documentation is incorrect; two lines need further indentation:

# 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"

should be:

# 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"

If you believe the documentation is incorrect, you can correct it. At the bottom of each page is an Edit button. It leads to Home Assistant’s documentation repository on GitHub where you can submit your modification.

Thank you @123. Part of my 6 hours was doing just that.