“messaggio” is an array with the value of power, energy and current. the template creates sensor.mqttenergy from the array. the array is sent each 30s.
I’m trying to solve this problem:
they suggest to use “availability” but I don’t know how implement it correctly…
The challenge you see with availability is the same root cause as the state; there is no value on an HA restart until the trigger is triggered. Hence the question to get you thinking why you are using a trigger when a trigger is the cause of the behavior. There are other mqtt sensors.
With an MQTT Sensor, if the the topic has a payload published as a retained message, the MQTT Sensor will always report the payload’s value, even on startup (i.e. it won’t be unknown).
Yes, It is correct the problem is the same like this post (and you have suggested the solution):
And you have replied: " Implement availability in your template sensors, based on whatever fits you.
If the availability is false, the template value will be ignored."
and now, I’d like to know how implement “availability”
See the response by taras.
As the template is only triggered by a message, the availability won’t be updated before a message comes in. Chicken, egg, …
They’re Trigger-based Template Sensors employing an MQTT Trigger.
The two concepts are different.
I guess that user overlooked to consider how their suggestion, to use a Trigger-based Template Sensor with an MQTT Trigger, behaves on startup.
FWIW, converting what you have into MQTT Sensors is trivial. Do you know if the payload published to the topic is a retained message? You can check by using an MQTT client like MQTT Explorer.
Personally, I’d go with @123’s suggestion and add them all as mqtt sensors. Using anchors it would be pretty simple as the value_template would be the only thing that changes if you set up the other fields properly.
The templates I posted in the example are probably wrong. I would need to see a sample of the actual payload in order to create the correct template. Corrected. Replaced value_json with value.
the problem is always the same… maybe I couldn’t explain myself…
after a restart the energy has a peak. the peak has the value of the sensor.mqttenergy, this sensor transmit a rising value (at the moment it is 6020577.0 Wh)… the graph should shows the difference between two readings, so normally few kwh (according the energy consumption of my home)…
I don’t know really if after a reboot the sensor has a unavailable or unknown status, I done a supposition because the graph doesn’t show the difference between two values