How to exclude an entity (switch) from recorder

I have an entity (switch.heartbeat) that changes state very frequently and it is flooding my database.
Already attempted to exclude it by inserting these statements into configuration.yaml but I still see the related entries into the database table events.

recorder:
  purge_keep_days: 5
  db_url: !secret db_url
  include:
    entities:
      - some
      - entities
  exclude:
    entities:
      - switch.heartbeat

history:
  exclude:
    entities:
      - switch.heartbeat

logbook:
  exclude:
    entities:
      - switch.heartbeat

Mine doesn’t look any different than yours. :thinking:

Are you sure, the name for the sensor is correct? Or could it be, that you see your old entries in the db? They won’t get deleted automatically if you change the configuration.yaml to exclude something.

I assume you did restart HA after your changes. :wink:

The old entries will remain in the database even after you exclude it, which only affects new entries. You can use recorder.purge_entities to purge the historical data.

Thanks for the replies.
The entity name is correct, I did restart HA, and I know that old db rows do not get deleted.
This switch is triggered by an automation, not sure if this makes any difference.
Here below are some db rows related to this switch.

MariaDB [homeassistant]> select * from events order by time_fired desc limit 10;
+----------+--------------+------------------------------------------------------------------------------------------------+--------+----------------------------+----------------------------+----------------------------------+-----------------+-------------------+
| event_id | event_type   | event_data                                                                                     | origin | time_fired                 | created                    | context_id                       | context_user_id | context_parent_id |
+----------+--------------+------------------------------------------------------------------------------------------------+--------+----------------------------+----------------------------+----------------------------------+-----------------+-------------------+
|  2389065 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:41.012457 | 2021-06-30 04:59:41.012457 | 401e044287209a9337cbd7891cb8b576 | NULL            | NULL              |
|  2389063 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:40.012826 | 2021-06-30 04:59:40.012826 | eaca56e5f9e8127692a03a39b0d3128f | NULL            | NULL              |
|  2389061 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:39.011834 | 2021-06-30 04:59:39.011834 | b0e80022ca428ed67dfcdcb7a7f3af5e | NULL            | NULL              |
|  2389059 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:38.012059 | 2021-06-30 04:59:38.012059 | 8f848d4d37a11f6f59228814894f4103 | NULL            | NULL              |
|  2389057 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:37.019648 | 2021-06-30 04:59:37.019648 | 6194190ca76245aa6e608a4a6ed6bc5c | NULL            | NULL              |
|  2389055 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:36.015049 | 2021-06-30 04:59:36.015049 | 8b4be3b67d909d7fdb0caf130cca05d7 | NULL            | NULL              |
|  2389053 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:35.014805 | 2021-06-30 04:59:35.014805 | 26283c503ad3dd899cdbd47eac77eab5 | NULL            | NULL              |
|  2389051 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:34.012122 | 2021-06-30 04:59:34.012122 | f87c5841ad2dfd856fad2641a17a0f7e | NULL            | NULL              |
|  2389049 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:33.015483 | 2021-06-30 04:59:33.015483 | cf7089247bb2fbe3904534679d65c16c | NULL            | NULL              |
|  2389047 | call_service | {"domain": "switch", "service": "toggle", "service_data": {"entity_id": ["switch.heartbeat"]}} | LOCAL  | 2021-06-30 04:59:32.012708 | 2021-06-30 04:59:32.012708 | 99b6ce7799f3472992e25806b1c8ef49 | NULL            | NULL              |
+----------+--------------+------------------------------------------------------------------------------------------------+--------+----------------------------+----------------------------+----------------------------------+-----------------+-------------------+
10 rows in set (0.002 sec)

Not 100% sure, but I think that excluding entities from the recorder will only prevent state changes to be recorded, i.e. event_type = "state_changed"

You could exclude call_service from being recorded with

recorder:
  exclude:
    event_types:
      - call_service # Don't record service calls

That did the trick!
Thanks a lot koying