MQTT and migrating from openHAB to Home Assistant

Hi,

I am migrating from openHAB to Home Assistant and would like to get some input on MQTT

In openHAB I have devices (ot Items in openHAB) configured like this

Number TotalPowerSensorWatt      "Total Power Watt" <energy> {
  channel="mysensors:power:gateway:sensor-total-power:watt", 
     mqtt=">
       [rabbitmq:/myhouse/power/sensor/total:state:*:Power,sensor=${itemName},location=total watt=${state} ]" }	

So when the device (a sensor in this case) get a changed state/measure it will post an event based on a template.
Here it will post:

  • To the topic "/myhouse/power/sensor/total"
  • With the payload "Power,sensor=TotalPowerSensorWatt,location=total watt=754"

How can I accomplish this in the best way in HA?

Note: I have MQTT connection enabled

An automation that triggers on change of state of your sensor and publishes the value using a template:

automation:
  trigger:
    platform: state
    entity_id: sensor.your_sensor_here # will trigger on any change of state if no state specified
  action:
    service: mqtt.publish
    topic: myhouse/power/sensor/total
    payload_template: "Power,sensor=TotalPowerSensorWatt,location=total watt= {{ states('sensor.your_sensor_here') }}"

I don’t really understand your payload but the example above shows how to insert a sensor value.