Put your mqtt package in and then you can test the value template beneath. Helped me a lot as I’m still very unsure about jinja2 and templating in general!
- platform: mqtt
name: temperature
state_topic: "tele/tasmota_377AE4/SENSOR"
value_template: "{{ value_json.TuyaSNS.Temperature if value_json.TuyaSNS.Temperature is defined else states('sensor.temperature') }}"
device_class: temperature
unit_of_measurement: '°C'
If value_json.TuyaSNS.Temperature is defined then it reports the received value, if it’s not then it reports the existing value by using states('sensor.temperature').
Please consider marking my post (above) with the Solution tag. Only you, the author of this topic, can do that. It will automatically place a checkmark next to the topic’s title which signals to other users that this topic is resolved. This help users find answers to similar questions.
will do, it came up unavailable at first, I added a space after states
not sure if it needed it or it was coincidence but it showed after another restart
The sensor’s value will initially be unknown until the first payload is received. Afterwards it will be either the received payload or its last value.
NOTE
Whatever Tasmotized device you have, that is publishing humidity and temperature, ought to be configured to publish its payload as a retained message. If it doesn’t then the humidity sensor you have will report unknown after a restart (of either Home Assistant or the MQTT Broker).