I’m currently working on a setup where I use PyScript to periodically trigger data retrieval from a Modbus TCP device. I then use state.set to send multiple data points back to Home Assistant.
While this approach works for real-time updates, I’m looking for a way to persist historical data so it can be displayed on frontend cards, for example, in a graph or history view.
I’m aware of solutions like using REST API or MQTT to create entities that can retain history, but I’m wondering if there are alternative methods to achieve this. Specifically, is there a way to create entities with history retention outside of REST API or MQTT?
If anyone has worked on similar setups or has experience with this type of use case, I’d love to hear your thoughts or see examples of how you’ve approached it.
To be sure we are not in a XY problem - Wikipedia situation, here:
Why are you using a PyScript to read the device rather than the builtin modbus integration?
Thank you for your response! I really appreciate your input and the time you took to share your thoughts.
I have tried using the Modbus integration, and it does work as expected. However, my target setup involves accessing consecutive registers and querying multiple devices. In my case, writing a Python script allows me to have better control over the flow, optimize the process for my specific needs, and handle the interactions with multiple devices more efficiently.
Thanks for the suggestion! Right now, I’m using the default Home Assistant database (home-assistant_v2.db) for storing data, but I’m wondering if there might be any issues with this approach. Do you have any other recommendations?
On the frontend, I’m using the apexcharts-card. Your suggestion about Grafana + InfluxDB sounds interesting, and I’ll definitely check it out to see if it works for my setup.
One thing I’ve been curious about: why does the Python state.set API only store data temporarily and not save it to the database? From what I’ve read, it seems like it doesn’t allow creating a persistent entity for storing values. It feels a bit restrictive—do you know why it’s designed this way? Would love to hear your thoughts!