Template Sensor based on MQTT and Z-Wave

Hi,
i combined a temperature sensor from my miflora via mqtt and some z-wave multi sensors. It works pretty fine, but not after the home assistant restart.
The mqtt sensors did not have any values after the system restart, so i always got some errors in my logfiles, unknown values in the frontend and spikes in my graphs.

So is there any possibilites to do some wait before the template sensor got created, or can i “save” the last value of my mqtt sensor over a HA restart?

Thx.

If you can get the miflora mqtt client to send the message with the retain flag set, which will tell the broker to re-send the message to any client that subscribes to that topic, such as when HA restarts.

However, the message stored may not be recent - the message is stored forever by the broker, so if your mi-flora stops working you may get a daytime temperature in the middle of the night. For this reason, it is more advisable to update your templates to handle the unknown state, and wait for a current message, rather than assume that the one stored in the broker is current.

Its not nesseccary that i have the latest value. I combine multiple temperature sensors in my rooms to get a correct room temp value. That is pushed to my thermostats to heat the room correctly.

So, if i have 2 values (21 and 23 C) it returns 22 C room temp ((21 + 23) / 2). But if i do not have the mqtt value i got 11,5 C ((0+23)/2).

I had a look at my mqtt client for mifora, but it seams that it did not have any “retain” flag.

Assuming the value is zero is not the same as ignoring it. If you ignore the unavailable, the result will be the same as averaging the two sensors you do have a value for. That is what your template should be doing.