Need help for mqtt_subscribe

Hello,

i want to display a HA Value to a LCD attached on ESP
The LCD is ready to use and i know that i must use the mqtt_subscribe

but can i become please a example how i publish the value of my sensor.tank_level to mqtt ?

like this ?

platform: mqtt
topic: home-assistant/tank/
payload_template: {{ states('sensor.tank_level') }}

State ? Value ?

Thank you

Hello Ingo,

are you looking for the subscribe syntax of esphome or the publish syntax of HA?
Your snippet looks like publish in HA, try:

payload_template: '{{ states('sensor.tank_level') }}'

Close but check your quote start and ends:

payload_template: '{{ states('

Use double quotes outside single quotes to avoid this:

payload_template: "{{ states('sensor.tank_level') }}"

Right, I was about to edit it but I canˋt find the proper double quotes on that shitty iPad…
Thanks for the correction.

I recently got rid of mqtt subscribe and just use the api, using the homeassistant sensor in esphome to get values from ha instead. This prevents error logs, and unnecessary overhead vs running api and mqtt together. I’m doing the same thing you are (displaying ha temps/humid/etc states on oleds).

If you have other needs, there is also the ha text sensor, etc.

sorry for the late response but i report that it works