I have a fully automated fish pond that changes a certain percentage of its water every week or so, I wanted to track the last water change via a sensor, for which I created an SQL sensor that retrieves state data from the home assistant DB states table, I sort the query data descending and I use the first state at the top to reflect the sensor value, which works fine until I restart home assistant and then the sensor value will be unknown, I looked at the SQL data for that sensor and there are lots of recent records with the UNKNOWN state for that sensor which is simply a variable.
So my question is, can I store the value of the sensor reflecting the last water change date somewhere, like in a file or any other means, then retrieve it when home assistant restarts, obviously I need a way to update the sensor saved value whenever the pond water change cycle finishes, is that possible?
When your water change automation runs you could store the date in an input_datetime as long as you don’t set an initial value in the configuration. This will be restored after a Home Assistant restart. It can also be edited manually if you do a manual water change.
Yes that is correct. As long as you don’t specify an initial value in the configuration. If you do that it will always be restored to the initial value instead when you restart.
Thanks again mate, I just have one question please, when I add the entity of the input_datetime to the entities card, a calnedar icon appears between the date and the time which allows editing too, can I disable that and remove that icon or is there any workaround that?
I came up with a solution, I just created a sensor based on the input_datetime you suggested and now I can view the sensor in the frontend instead of the input_datetime and I don’t get that calendar icon nor the sensor’s value can be changed
I like your idea of updating the date when I do manual water change as I do have a switch to intiate the water change script manually if I need to, so I will expose editing the input datetime as per your idea