The home assistant database is just sqlite3, and it’s pretty easy to use. There’s a command line tool that you can use to poke around at the database, or you could use a python library.
Using the command line tool, you can query the states table for the relevant entity. Here’s just a quick hack to grab the last few measurements from the table:
louie@hass[221] $ sqlite3 -csv /tmp/home-assistant_v2.db
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> select created,entity_id,state from states where entity_id='sensor.ow_outside_h_temp' order by created desc limit 20;
"2019-05-31 01:44:47.602685",sensor.ow_outside_h_temp,73.0
"2019-05-31 01:43:42.574080",sensor.ow_outside_h_temp,72.8
"2019-05-31 01:43:10.123315",sensor.ow_outside_h_temp,72.7
"2019-05-31 01:42:37.538063",sensor.ow_outside_h_temp,72.8
"2019-05-31 01:42:05.088129",sensor.ow_outside_h_temp,72.7
"2019-05-31 01:40:59.821806",sensor.ow_outside_h_temp,72.5
"2019-05-31 01:40:27.387789",sensor.ow_outside_h_temp,72.4
"2019-05-31 01:39:54.709631",sensor.ow_outside_h_temp,72.7
"2019-05-31 01:39:22.264257",sensor.ow_outside_h_temp,73.0
"2019-05-31 01:38:49.637563",sensor.ow_outside_h_temp,73.2
"2019-05-31 01:38:17.252672",sensor.ow_outside_h_temp,73.0
"2019-05-31 01:37:44.669761",sensor.ow_outside_h_temp,72.7
"2019-05-31 01:37:12.210474",sensor.ow_outside_h_temp,72.5
"2019-05-31 01:36:39.676839",sensor.ow_outside_h_temp,72.3
"2019-05-31 01:36:07.192790",sensor.ow_outside_h_temp,73.0
"2019-05-31 01:35:34.566064",sensor.ow_outside_h_temp,73.1
"2019-05-31 01:35:02.121316",sensor.ow_outside_h_temp,73.0
"2019-05-31 01:34:29.579887",sensor.ow_outside_h_temp,73.2
"2019-05-31 01:32:51.979445",sensor.ow_outside_h_temp,73.1
"2019-05-31 01:31:14.581173",sensor.ow_outside_h_temp,73.2
sqlite>
You could push your data into influxdb and point grafana at influxdb to generate pretty graphs. Or even use the influx to run queries on the data and extract a series. I have a bunch of states that get pushed into influxdb, a really nice time series database. This example is also just temperature, but I also have AC line voltage, power measurements, DC battery level of the generator’s starter battery, etc. in there.
Just a quick dashboard that took 2 minutes to set up in my grafana/influx installation:
There’s a bunch of tools at your disposal that might be a more rapid path to a solution. In my circumstance, I have Home Assistant, influxdb and grafana running in different docker containers that we each fairly easy to get setup. If you’re using Hass.io, there are probably pre-built extensions that you can click to install pretty easily.
Regardless of what path you go down (even using the home assistant database), just try to be aware of the I/O load going to the database. The SD card on a Raspberry Pi is really going to struggle if you’re trying to push a bunch of data into it. I’m running Home Assistant on a NUC-type device with an SSD, and the I/O performance is just not any issue in that environment. To help manage this, if you’re using the influxdb component in Home Assistant, you might want to be selective in only having it store the sensors that you care about in there, and not ones that changes on a frequent basis that don’t have any interesting data .