Update MQTT topic based on a sensor value

Hi,

I have connected HA to my MQTT broker. Connection works. As I want to use some information on another system, I want to write data from a HA sensor to the MQTT broker.

I have a sensor called

sensor.blitzortung_lightning_counter

which can assume a number of 0 and above. Now whenever it changes, I would like to write it into the MQTT topic

HA/lightning_counter

Is there any code which I can put into the configuration.yaml to do this? Can you help me with this? :slight_smile:

Johannes

You need an automation for this, read the docs first here.
The trigger will be your sensor changing state and the action will be publishing the state to an MQTT topic.

1 Like

Someone else asked a similar question and I posted an example here:

1 Like

Thank you both. What I have found after I created an automation, is mqtt_statestream, which does what I need and which also has a quite straight forward configuration.