Post sensor values to MQTT

Correct.

If you want to publish your RESTful sensor’s state to an MQTT topic, use an automation.

- alias: 'Publish sensor value'
  trigger:
    platform: state
    entity_id: sensor.my_sensor
  action:
    service: mqtt.publish
    data_template:
      payload: "{{trigger.to_state.state}}"
      topic: whatever/topic/you/want

If you want to publish the states of several sensors yet with only one automation, you could use something like this:

- alias: 'Publish multiple sensor values'
  trigger:
    platform: state
    entity_id: sensor.my_sensor1, sensor.my_sensor2, sensor.my_sensor3
  action:
    service: mqtt.publish
    data_template:
      payload: "{{trigger.to_state.state}}"
      topic: "sensor/{{trigger.to_state.object_id}}"
10 Likes