Allow services to be excluded from Recorder: and the database

The Recorder: component allows for the exclusion of entities. I would like to have the ability to exclude the services below. I have to delete these events from the database every 10 mins which from what I observe, compose 95% of the size and rows of the database while not doing anything for the logbook. Thanks

#!/bin/sh
mysql -uhass -phass HOMEBASE --execute="USE HOMEBASE";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'service_removed'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'service_executed'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'platform_discovered'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'homeassistant_start'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'feedreader'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'service_registered'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'call_service'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'component_loaded'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'logbook_entry'";
mysql -uhass -phass HOMEBASE --execute="DELETE FROM events WHERE event_type = 'system_log_event'";
mysql -uhass -phass HOMEBASE --execute="OPTIMIZE TABLE EVENTS;"

I don’t think it’s documented, but you can. E.g., I have:

recorder:
  exclude:
    event_types:
      - component_loaded
      - platform_discovered
      - service_registered

EDIT:

Apparently it was added in PR #7627, which made the 0.46 release almost 2 years ago. Documentation requirements must have been more relaxed back then. :wink:

7 Likes

Thanks, it seems to work great. Only state changes recorded. It would be nice to have an include filter as well so I can just include state_changes instead of excluding everything else.

recorder:
  db_url:   mysql+pymysql://hass:[email protected]/HOMEBASE
  include:
    domains:
      - sensor
      - switch
      - shell_command
      - binary_sensor
      - input_text
      - light
      - script
 #     - device_tracker
  exclude:
    entities:
      - sensor.time
    event_types:
      - service_removed
      - service_executed
      - platform_discovered
      - homeassistant_start
      - feedreader
      - service_registered
      - call_service
      - component_loaded
      - logbook_entry
      - system_log_event

Amazing how much this help, it should be put in the documentation. Thanks again.

4 Likes

I tried to find out how to add this to the official documentation but I am unsure how. Please add to the official documentation as I think its a really important feature that will make most peoples HA run better. I would even suggest state_change only events be recorded as default.

1 Like

Just to update of what my database looks like after 2 days, 8MB and 14k rows.

recorder:
  db_url:   mysql+pymysql://hass:[email protected]/HOMEBASE
  exclude:
    event_types:
      - service_removed
      - service_executed
      - platform_discovered
      - homeassistant_start
      - homeassistant_stop      
      - feedreader
      - service_registered
      - call_service
      - component_loaded
      - logbook_entry
      - system_log_event
      - automation_triggered
      - script_started
      - timer_out_of_sync
5 Likes

After 12 days with more than 50 plus sensors.

1 Like

For some reason, the database is getting smaller. My HA has not been changed since my last post but my database is about 1/2 the size.