Getting MQTT working via Python

I used to have a working MQTT setup, but with the new changes I’m missing something.

I’ve created a sensor in configuration.yaml:

mqtt:
  sensor:
    - name: "macropad"
      state_topic: "home/macropad"
      device_class: temperature
      unique_id: my_mqtt_temp
      name: my_mqtt_temp
      unit_of_measurement: 'F'
      availability_template: "online"

I can see the sensor, with a value of ‘unknown’.

I send data via python:

def send_data():
    state_topic = "homeassistant/macropad"

    publish.single(state_topic, "42",
                   hostname="homeassistant.local")

I do appear to send the data. I can see the message arrive when listening to it in the setup.

However my value for the sensor never updates. It stays at ‘unknown’. What am I missing?

Your state_topics aren’t the same

1 Like

Thank you! I spent way too long overlooking that. It is now working. I appreciate the help.

Happens to all of us. Glad it worked out