Graphing sensor value over time - without InfluxDB

I’d like to track a numeric sensor value (such as current draw on a smart outlet), recording measurements every few minutes, and then graphing them. Is there a good method to do this that doesn’t require InfluxDB?

I’d love to have the graph be right in HA, but I can also live with a csv export (with timestamps, ideally) that I can then plot in Excel or something. I’d prefer solutions that don’t require cloud access of some sort - it’s not that this is super private, but I don’t want to deal with yet another account for something that I really don’t need to ever access remotely…

I suppose I could write an AppDaemon script that polls the sensor on some sort of schedule and writes the values to a csv file, but it seems like reinventing the wheel…

(I know lots of people like InfluxDB/Grafana for this, but I cannot make it work - see my posts here: Home Assistant Community Add-on: InfluxDB if you think you can help with that part of it, I’m making this thread to look for alternatives)

I just set something similar up using Google Sheets, but would love to hear other ideas folks have on the best way to accomplish this. To your point, I may have reinvented the wheel unnecessarily…

This is for a sensor that measures current draw on our electric car charger. I am using a python script to query the HA database and write the output into a Google Sheet. I have pivot tables and charts referencing the data table, which I then use to pull data back into HA along with an iframe of one of my charts.

Literally set this up just this week, so time will tell if this will be a reliable way of graphing data. After a couple weeks I’ll probably need to revisit and start grouping the data by week number and eventually month.

image

1 Like

You can graph right in HA using the History Graph component, but it’s limited to the data saved by the recorder, which is (generally) periodically purged. So it depends on how much data you want to graph.

Another way would be to use the File Notification component. You could have an automation that triggers periodically, or maybe better yet, whenever the sensor changes, and then writes to that notification. You can use a template to format the data written to the file. If this sounds like something you think might satisfy your needs, and you’d like an example of how you might use it, let me know.

1 Like

That could work, so yes, I’d love an example.

When you said you grab it with a python script, do you mean in AppDaemon, or something running outside HA entirely? I’m using Hass.io, so not sure there’s external access to the db, since it’s all containerized and such.

Also, this made me think that I should probably put a power meter on my car charger as well, that seems like useful info… :slight_smile:

1 Like

You could use the data-detective to create a plot script in python, then use a shell command to periodically call the script

1 Like
notify:
  - platform: file
    name: my_sensor_notify
    filename: my_sensor.csv
    timestamp: False
automation:
  - alias: Update my_sensor log
    trigger:
      platform: state
      entity_id: sensor.my_sensor
    condition:
      condition: template
      value_template: >
        {{ trigger.to_state is not none and
           trigger.from_state is not none and
           trigger.to_state.state != trigger.from_state.state }}
    action:
      service: notify.my_sensor_notify
      data_template:
        message: >
          {{ now() }}, {{ trigger.to_state.state }}
1 Like

Ah, yes my script runs outside of HA (not using Hass.io), sorry!

1 Like