Sending data from HA using mqtt

Hi, I have a entity (sensor.t_h_sensor_temperatura) and want to send the data using mqtt to another mqtt (Venus OS). The payload must be like this:

{“grid”: { “power”: x.x } }

x.x is the value of temperature of the sensor (sensor.t_h_sensor_temperatura) as I’m really noob I don’t know how to extract the value of temperature from the entity to put it in the payload.
Thanks

i’d do an automation, triggered by a change in sensor status, calling the mqtt publish service and filling the payload with needed information
try and see :slight_smile:

Thanks, I know the way to do (I can send a number) but missing the detail, the temperature is in sensor.t_h_sensor_temperatura and I don’t know how to extract the value.

In theory, this should work

  action:
  - data:
      payload_template: '{{ {“grid”: { “power”: states('sensor.t_h_sensor_temperatura') } } }}'
      topic: your_topic
      retain: true
    service: mqtt.publish

but I suspect ninja/HA will complain about the {

so maybe

  action:
  - data:
      payload_template: >
        {{ '{%raw %}{"grid": { "power":{% endraw %} states("sensor.t_h_sensor_temperatura") {% endraw }} }' }}
      topic: your_topic
      retain: true
    service: mqtt.publish

First one delivers this {“grid”: { “power”: states(‘sensor.t_h_sensor_temperatura’) } } as a text not the value inside sensor.t_h_sensor_temperatura.
Second one a error:
Error: TemplateError: TemplateSyntaxError: Encountered unknown tag ‘endraw’. rendering template, template: ‘{%raw %}{“grid”: { “power”:{% endraw %} states(“sensor.t_h_sensor_temperatura”) {% endraw }} }’ and payload: None

Works, BUT very confused, this is on automation edit:
payload: “{ "grid": { "power": {{states(‘sensor.t_h_sensor_temperatura’) }} } }”

this in text editor
payload: ‘{ “grid”: { “power”: {{states(’‘sensor.t_h_sensor_temperatura’‘)
}} } }’