History of sensor attributes

Hopefully this is an easy question: Does home assistant record the history of entity attributes, and if so, how would I access that information?

I know that I can set up a template sensor to record this data, but in this case I’m looking to understand something that already happened. So I didn’t have the foresight to set up a sensor.

I want to look to see if my thermostat changed modes, and I already know it wasn’t something commanded by HA. So I’m just looking to see if it was reported to, and recorded by, HA. It would be an attribute of an entity in the climate domain.

1 Like

I think HA itself doesn’t note down the value of attributes in the logbook/history.

For myself I use influxdb and I see that attributes are transferred there as well - so the influxdb integration might be interesting for you.

Yes, I think you’ll find this data in the states and events tables in the Recorder database.

As I understand it (and I’m just a user) there’s an entry in the states table every time an attribute changes. The attributes are stored in a TEXT field named - surprise - attributes. Here’s an example from one of my climate entities:
{"hvac_modes":["off","cool","heat"],"min_temp":40,"max_temp":90,"fan_modes":["on","auto"],"preset_modes":["none","away","Hold"],"current_temperature":65,"temperature":65,"target_temp_high":null,"target_temp_low":null,"current_humidity":128,"fan_mode":"auto","hvac_action":"fan","preset_mode":null,"fan_action":"running","permanent_hold":false,"dr_phase":-1,"friendly_name":"1st Floor","supported_features":27}

In the events table, every change you make is apparently recorded in the event_data table. Here’s an example from another climate entity of mine:
{"domain":"climate","service":"set_temperature","service_data":{"temperature":68,"entity_id":"climate.guest_rm"}}

Not sure what your purge_keep_days is set to. The default is 10. If it’s getting close to that, you might want to make a copy of your database now and play with that off line.

1 Like

Yes it does record attributes.

You have three options available to you:

  1. Create a template sensor that is based on the attribute value and use the core history graph

or

  1. Use the custom card Apexcharts.

or

  1. Use the custom mini-graph card.

Bot of the last two options support graphing attributes directly. Though they won’t be much use for text based sensors, like your requirement.

If there are only two modes you could create a binary sensor that they can graph.

1 Like

Thank for this. Since I use MariaDB I had to install https://github.com/hassio-addons/addon-phpmyadmin and then I was able to find the entries and export them to CSV to review them.

I didn’t use these options because I understand option 1 is only useful to graph future data, not past data. And as you noted, options 2 & 3 won’t work for text.

In the end I discovered my thermostat (Google Nest) stopped heating for several hours today (hvac_action was “idle” even though current temp was below the set temp). I was expecting to see the preset_mode change from “none” to “eco” but it didn’t. I’ll have to dig into this some more to see what the thermostat reports when it detects nobody is home. But this got me the data I was after, thanks!

Thanks, I just added this & Grafana and it will be very useful in the future. Doesn’t help with looking at data prior to setting it up, but if this happens again I won’t have to go looking in my MariaDB.

I am trying to do the same thing and I am looking at the Recorder db in DB Browser for SQLite. The problem I am having is that I can’t find times for when the attributes change.

I am looking in the event_data table. I see the attribute changes I am interested in. But I don’t see any times associated. There are just 3 fields. data_id, hash and shared_data, and none has the time.

Likewise, I can see the changes I am interested in in the state_attributes table, but again, no times :frowning:

I have a feeling these times must exist somewhere though. I was trying to get view the data using the mini-graph-card custom card. Though it doesn’t show me the data I want (because it’s text, not numbers), it does appear to show the history of some number attributes. This is a climate entity and it is showing set and current temperatures with history.

Oh, then again, in the db, those particular attributes are stored in the states table… Hmm. It appears that some attributes get recorded in the states table with times, and some don’t. Is that my issue?
FWIW I am looking for the FanMode and SwingMode settings for the climate entities.

Many thanks in advance for any advice…

Guys, sorry but I didnt get how to see on events table or State Table.

Could, please, someone explain a bit more? More like a step by step.

Tks

You’re probably best off starting a new topic; the database has been refactored since this thread was solved. And the instructions will be different depending on what database you are using and what you are trying to do.

1 Like

Tks, Rick.

I guess my mind was a bit off because when I read table I was thinking an UI table.

I’ll check the database