tirsdag den 17. januar 2017

A note on Home-Assistant and SD-cards

(Beware of) Killing your SD-card

If you use hass on a raspberry pi, make sure you don't write a lot to your SD-card.

Well this warning goes for anything running of a sd-card, but what I've noticed however is that hass really writes a lot to the card.

My fist SD-card didn't last for more than two weeks, but it was a cheap one, and I've used it for many other tasks, so I though it had just reached it's end of life.

But when my new 16 GB kingston card died after 2 months, so I though I'd better take a closer look at what was going on.

In the default configuration file, two components are enabled by default:
logbook and history.

recorder

This component is used by history (see next section).
Url: https://home-assistant.io/components/recorder/

It specifies what backend to use, and how mush data to keep.

history

If we take a look at history (https://home-assistant.io/components/history/), it creates a file called "home-assistant-v2.db" in your configuration directory (unless you're specified another path in the recorder component).

It logs state changes, so only writes to the database when something changes.

Note that you can exclude certain entries from being logged.


Logbook

This element writes
It writes to this file EVERY second!
It does this to log the state of your system, but COME ON, every second!?!?!


A better way would proberly be just to log state changes.
It would both reduce the number of entries, and the load on the SD-card.
Now I don't know yet how logbook logs it's entries, but it might do the same thing.

Fixing it

A couple solutions are available (that I'm aware of):
  • Log to non-flash storage
    Either attach a harddrive, or over the network.
  • Disable the components
    Just comment-out the lines in the configuration file.
  • Save the file(s) on a RAM-fs and then once a while save it to disk
    It's easy to use tmpfs.

For now I've just disabled the components.


1 kommentar:

  1. Recently bought a microSD card from eBay, but it turned out to be a complete fake. Make sure you do your homework before you buy from eBay, as many of the SD cards are counterfeits.

    SvarSlet