Sensor value send mqtt

How can Í send a sensor value with mqtt push service? What should be written in payload field?

This automation publishes the state value of sensor.temperature to the MQTT topic home/temperature every time the value changes.

alias: example 1
trigger:
- platform: state
  entity_id: sensor.temperature
action:
- service: mqtt.publish
  data:
    topic: home/temperature
    payload: "{{ trigger.to_state.state }}"

Templates - State Trigger

Thank you,

It works.

Glad to hear that it solved the problem.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been solved. It helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

1 Like