I'm confused about recorder/history/logbook components

This seems like a dumb question, even for my standards, so go easy on me!

In an effort to minimise writes to my database, I’m trying to stop certain entities states being recorded.

I have an exclude section in my configuration, but I still see history stats when I click on the entity?

Some entities I have ‘excluded’ show no stats, some do show stats?

So, I guess my question is in 2 parts

  1. How do I stop states of entities being saved to he database?
  2. What is the difference in usage between the history, recorder and logbook components?
    Should I have an ‘exclude’ for each component I’m not wanting history for in each of the above components.

Might be a help if you post a copy of what you have done in your config.

"The ‘recorder’ component is responsible for storing details in a database, which then are handled by the ‘history’ component. "

As per the doc here… https://www.home-assistant.io/components/recorder/#exclude

For mine the things I dont want recorded into the DB I have added them to the recorder config.

recorder:
    db_url: !secret mysql_url
    exclude:
    domains:
        - weblink
        - group
        - history_graph
        - sun
    entities:
        - binary_sensor.remote2_motion
        - sensor.date
        - sensor.date__time
        - sensor.internet_time
        - sensor.load_1m
        - sensor.time
        - sensor.time__date
        - sensor.time_utc
1 Like

I have switched from exclude to include only for the recorder component, i.e. not using an exclude only shows the ones you include.

This brought he size of my database down from 3GB for 3 days worth of recording to about 170MB for 3 days.

3 Likes

Ah ok, this answered a question…if I have only an include, will it exclude everything else not in the list?

My recorder.yaml looks as follows:

  purge_keep_days: 3
  purge_interval: 1
  include: 
    entities:
      - device_tracker.rich_phone_s8
      - light.bedroom_light
      - light.lounge_lamp
      - media_player.bravia_tv
      - sensor.speedtest_download
      - sensor.speedtest_upload
      - sensor.speedtest_ping
      - sensor.tv_watched_this_week
  exclude:
    domains:
      - weather
      - sun
      - device_tracker
      - switch
      - weblink
      - sun
      - weather

But I’m still seeing some sensor components with history?
And my history.yaml is

  use_include_order: True
  include:
    entities:
      - device_tracker.rich_phone_s8
      - light.bedroom_light
      - light.lounge_lamp
      - media_player.bravia_tv
      - sensor.speedtest_download
      - sensor.speedtest_upload

But I still see history for some sensors, such as pi-hole sensors…note they don’t appear on either include list?

history basically controls what will be shown on the history page. Recorder controls what will be stored in the DB.

BTW I found that moving over to MariaDB/MySQL really helped my speed and disk usage. My DB is currently less than 800MB and I have data going back to 25th August in there.

1 Like

This is what’s confusing me.
I have entities in the exclude section of recorder.yaml, but still see history? (By means of having an include only section)
I assumed that if they are excluded from recorder, I’d see no stats?

can you post the relevant parts of your config, it might make it easier to see what you have and what might be happening.

You have not excluded the sensor domain for the recorder, so they will all be recorded.

The sensor entities you include do not have an effect because none of the sensors are excluded from the recorder in the first place, i.e. you include something that hasn’t been excluded:

      - sensor.speedtest_download
      - sensor.speedtest_upload
      - sensor.speedtest_ping
      - sensor.tv_watched_this_week

Because none of the sensors are excluded in the recorder, you can include them in the history, but - as you have no exclude here at all - you will only see in the history what’s included in the history.

Same is valid for the light and the media_player domains.

You should not be able to see any of the latest status updates for the device_tracker.rich_phone_s8 in the history, because you excluded all device trackers from the recorder.

I posted them above.

Ah, ok. Thank you!
It was a complete lack of understanding on my behalf! :man_facepalming:
So the logic is…

exclude:
  - component [everything for these domains]
include: 
  - [ except these specific named ones]

I was thinking that if I have only an include in the recorder component then everything else is excluded

Sorry missed that you had posted your config (was late)

you can do it either way around.

exclude:
  - domain [everything for these domains]
include: 
  - [ except these specific named entities]

or

include:
  - domain [everything for these domains]
exclude: 
  - [ except these specific named entities]

as per this example from the docs

# Example configuration.yaml entry with include and exclude
recorder:
  include:
    domains:
      - sensor
      - switch
      - media_player
  exclude:
    entities:
     - sensor.last_boot
     - sensor.date

If I recall correctly you can use also use the “whitelist” method which excludes everything else if you ONLY have includes.

# Example configuration.yaml entry with include and exclude
recorder:
  include:
    domains:
      - switch
      - media_player
    entities:
     - sensor.last_boot
     - sensor.date

thanks @allan
I think I will go for the method of excluding everything, except…my logic being as my install grows it should help managing the list be a little easier, rather than listing many entities to exclude.

Will this work, when you don’t have ‘sensor’ in domains?
I ask because mine isn’t working without, but then I get ALL sensors in, unless I exclude them. But that’s a huge job…

can you post the section of your config you are having trouble with?

also where are you meaning you get all sensors in?

Now I’M confused. After setting it up again, it’s actually working. I wanted only 3 sensors in my history. Not all of them. And I think I did the same, the second time. But apparently not. Anyway, it’s working.

recorder:
  purge_keep_days: 5
db_url: mysql://***********************
  include:
    domains:
      - light
      - switch
      - media_player
    entities:
      - sensor.daylight
      - sensor.memory_free
...
...
1 Like

cool, as long as its working.

1 Like