HA is very unstable

I have been using HA on a Raspberry Pi for close to two years. It was solid as a rock for about 6 months where it turns out my memory card died. Ok, bought a new card, restored snapshot and everything was good for another 6 months. Not a big deal as this wasn’t a HA issue. Then early this year, February maybe, it stopped working again. Thought it was the memory card so I replaced it. Then it stopped working the next day so this wasn’t a memory card issue. Power cycled the Pi and it was fine for 3 days then it stopped working. Repeat this with varying durations. Then the Pi went 30 days with no issues so I thought there was a bug in one of the versions and it was fixed. Well yesterday morning it stopped working so I power cycled the Pi and then this morning the same thing. This is getting very annoying and I’d like to fix this.

By not working I mean I can’t access the web site nor ssh into the Pi.

1 Like

Do you have another RaspberryPi you could try?
Do you have a different power supply for the Pi? They are picky about the power supply.

I know someone who had the same type of issues. I found, when using the Glances add on, that the swap file on the pi was filling up then locking the pi up. There are guides on how to increase its size and his Pi and HA have been solid since. Think he raised it from 100meg to 2gig but he is running HA and the pi from SSD so you may need to keep it a little smaller.

Warning - you are running from an SD card so the writes to it will increase doing this and it will wear out sooner. Would highly recommend moving to SSD if you can before increasing the swap size.

I do not have a spare Pi or spare power supply.

I was thinking about switching to a better storage system but I am not sure how. Any guides on this? I am a Windows developer, Linux is very new to me.

Finding a solid power supply for your Pi might be the cheapest option to eliminate it as the source of your problems. If you bought the Pi from a kit like CanaKit then you already have a decent power supply. I only suggested this because it is a fairly common issue with instability on Pi hardware.

Install the custom integration Raspberry Pi Power Supply Checker. It’ll tell you if your power supply is the issue.

1 Like

I have been running HA on a Pi3, Pi3b+ and now a Pi4 for nearly 3 years and its a great way to start and build up your skills with Linux first before you move over to higher spec devices.

There is a dedicated HA OS build that you should be able to flash straight to SSD from memory but you will need to enable USB boot on your pi first using this guide

I would start with increasing your swap file to 1GB first and see if your pi is stable again - easy guide here

1 Like

From your symptoms I would agree with the already mentioned swap file hypothesis. Hit me when installing HA as well. Solved it by following a tuto to make its size dynamic. I also moved tthe system to an external SSD ASAP. SD cards are not meant to run an OS and burn too quickly. It doesn’t take long for a small mSATA SSD to become the cheaper option, compared to buying a new microSD card every few weeks.

Since you’re new to unix-like ecosystems, I’d also recommend that you regularly check that your /var partition (if any) or your / partition (if no dedicated partition for /var) does not get overcrowded. It hit me a few days ago on a NextCloud server where I forgot to disable verbose logging. /var gets full, nothing can write logs to /var/log anymore, everything locks up. The difference being that a reboot would not have saved you in that case.

Regarding the power supply suggestion, I do remember seeing messages saying that an undervoltage was detected. The Pi is hooked up to a UPS so I didn’t think much of it.

I tried following the guide (above) to increase the swap file. When I ssh into HA I do not have the file /etc/dphys-swapfile and the command sudo dphys-swapfile swapoff fails with error command not found

I’ve wanted to replace the SD card with a better storage device. I read the guide (above) to change the boot for the Pi but the idea that it is permanent scares me because I’ll likely brick my Pi. Plus I am running Hassio so I am not fully understanding where the Pi configuration ends and Hassio begins.

An undervoltage message suggests your power supply is at least suspect. This has nothing to do with whether attached to a UPS or not.
If you’re running Hassio on your Pi then you would not be able to change the swap file size as the HassOS would not permit that. You could always enable system metrics and monitor the swap area to determine if this is even a concern.
What Pi are you running because I believe that 3 and I know 3+ allow booting from usb storage natively (no changes required).

I am running the 3+ I believe

Just check my Amazon order… Raspberry Pi 3 Model B

Just checked, the native boot is only on 3B+, you have to enable on earlier models.
To tell you the truth, I would monitor the power supply because you can do that for free. If it’s the power supply that’s a cheap fix.
If you go the route of usb boot be aware you have to pick you drive and connectivity kit carefully as not all combinations will provide boot capability. Also Home Assistant (hassio) can boot from usb if your Pi is capable. I currently boot Home Assistant on my RPi 3B+ using a Kingston 120GB A400 SSD and Sabrent USB 3.0 to SSD I/II/III Hard Drive Adapter. No sd card required.

My new power supply will here Monday.

So if I buy a 3B+ it has native USB boot support. So how do I get HA on an external drive? Just use etcher to write the image to an external drive? Or is there more to it?

Don’t but another Lie if you want to use an external SSD; get Our with USB3 to have reasonable storage performance. And you can easily configure it to run with the root filesystem on the SSD, shortly, event to boot from it. I have a Pi4 (not running home assistant) that boots from the SD card and runs from the SSD otherwise. Big improvement in performance, and you won’t smoke the SSD with a heavy write load.

Same process. You would just plug the SSD into your pc and use etcher to put the system on just like you did for the sd card. Of course the Pi4 is also out. OS was just updated recently and will probably be bootable with Home Assistant in the near future although not today without an sd card. There are many options.

The procedure to enable USB boot on the Pi3 is very easy and there is little chance of it going wrong. Once it is enabled it will work as a Pi3B+ does natively.

I run 2 Rpi’s - a Pi4 is my main HA and a Pi3B+ for things like the Adguard add on and Zigbee2Mqtt. I used to run a Pi3 (and 3B+) from SSD and when I moved to the Pi4 I just removed the SSD from the Pi3 and added it to the Pi3B+ and it booted fine.

I would recommend a Pi4 for running HA but if you have a Pi3 that is great to start with.