Automation to publish temperature on MQTT - need help

Hello
I have some sensors connected via Homekit. I can see the values in Lovelace frontend.
I want to send the temperature value every x minutes on my MQTT server.
I’m unable to recover the sensor value to publish it, could you help me to discover what I made wrong ?

My automation is

  • id: ‘1999999’
    alias: TempExt
    trigger:
    minutes: /1
    platform: time_pattern
    action:
    • data:
      payload: {{sensor.temperature_and_humidity_sensor_9999_temperature}}
      topic: mytopic
      service: mqtt.publish

When the payload is a numeric value manually entered (ie 5) = it works.
I tried the payload without {}, with one pair, whith 2 pairs = still KO

Thanks for your help
Lionel

Update
I made tests using mqtt.publish service in the dev tools on the HA front-end. I can now see directly the result.

payload_template: ‘{{ sensor.temperature_and_humidity_sensor_999_temperature }}’
–> UndefinedError : ‘sensor’ is undefined

payload_template: ‘{{ temperature_and_humidity_sensor_999_temperature }}’
–> published, but no data

payload: 55
–> published with the good data

My conclusion, I have a problem in template evaluation to recover the temperature of the sensor
Ant idea ?

Hi @LL91, did you manage to publish the temperature every minute? I need to do this too :).

yes I use an Automation
with trigger - Time model envery /5 minutes
with action :
data:
payload_template: ‘{{ states.sensor.nameofmysensor.state }}’
topic: myMQTTtopic
service: mqtt.publish

and multiply this block for each sensor