Sorry about that; my mistake. Home Assistant’s Jinja2 interpreter attempts to evaluate this template
{{ value_json.temperatura }}
before the payload is published. We don’t want the jinja2 interpreter to evaluate it so we wrap the template in raw/endraw tags as shown below:
service: mqtt.publish
data:
topic: homeassistant/sensor/temperatura_dnevna_test/config
retain: false
payload: |
{
"name": "Temperatura Dnevna Test",
"unique_id": "esp9_temperatura_dnevna_test",
"state_topic": "home/esp9/dnevna",
"value_template": {% raw %}"{{ value_json.temperatura }}"{% endraw %},
"device_class": "temperature",
"unit_of_measurement": "°C",
"icon": "mdi:gesture-double-tap",
"device": {
"identifiers": ["esp9"],
"name": "ESP9",
"model": "ESP8266",
"manufacturer": "Espressif",
"sw_version": "1.0"
}
}
Here’s the result after I click Call Service and publish a JSON payload, containing the temperature, to home/esp9/dnevna
.
The sensor’s appearance in the UI: