Mqtt sensor with username and password

hello all,

i would like to integrate a sensor via mqtt. the data is sent from an electricity meter to an external mqtt server. this is protected via username and password.

can i define a mqtt sensor in home assistant and include this topic as sensor? I can at least listen to the topic via the HA mqtt integration and get the correct values, but is it also possible via configuration.yaml? I run HA as a pure docker installation


sensor:
  - platform: mqtt
    name: "Strombezug"
    state_topic: "vzlogger/data/chn0/raw"
    unit_of_measurement: kW

Yes you can if you first add the mqtt broker integration for the external server and user/password.

It’s working now. I had to restart HA. thanks!