I have many mqtt sensors defined, connecting to my Z-wave hub and reading current and total energy consumption, and also reading the data from my smarte meter. All doing well.
Only issue i seem to encounter is that between reboots of HA, all sensors need te repopulate. And data is only collected when pushed (published) on the Hub.
Doesn’t HA read the latest states from memory somehow, or isn’t this data stored in a DB?
The need for repopulating isn’t very elegant, and more importantly, very impractical, when the read data is supposed to be source for further action in automation…
Please help, i might be off, or very close to a solution im not aware of yet
If HA has just started, it doesn’t have it in memory. I think HA could read from the database, but it doesn’t.
You can change your sensors to publish MQTT messages with the retain flag. That will ensure the broker will send the last MQTT message when HA starts up again, and populate the front end that way.
ive defined the sensors to read a certain topic from the hub, the hub just sends all events to the Mqtt broker. i don’t think i can change the way the publishing is done, ill ask the dev op the hub though if that would be possible.
its not a matter of defining some kind of setting in the HASSIO for retaining the last value? that would be super practical…
reading from the DB: it’s not done, or is it not possible? Maybe there’s a setting there too?
btw, i have the built-in add-on enabled (maria DB). is that what it writes to? on regular basis i see the db with -shm and -wal extension in the finder. Seems like temporary settings being written to the db?
If the Maria DB is something else, what would be the use for the then?
The way i get around this issue you have, is to use a custom component as seen here Variable. it allows to store values, and reload even after a full reboot of the system by reading from the DB.
In my setup, I have all my mqtt sensors, storing their values in their respective variables, and I just reload everything when the system starts up.
sounds exactly like what im looking for. Especially since the hub doesn’t always send events, only when they happen. Which in case of many switches and even smart meter value registers is quite often. Or my solar panels, when rebooting in the evening. Nothing to report, so the Front end says 'Unknown"…
reading from last written memory would solve this. Cool, ill check this out and hope it works!
Thx,
Marius
please let me get back on this, now I’ve settled somewhat in the Mqtt Sensor configuration. Would you care to share an example of your config using the variable?
Thanks,
Marius
You’d think this to be possible too when not configuring HomeAssistant as the publisher, but, as in my settings, a wave hub to which the Homeassistant instance subscribes?