Home Assistant UPS Mk II Plastic Case

I’ve put the UPS in a case. I was going to 3D print a case, but that’s a lot of plastic, so I just put it in a generic plastic container:

HA UPS Mk2 Block Diagram

The lid keeps the dust out, inside I have put bits of cardboard in to keep things apart.

HA UPS Mk2 Block Diagram

I’m not going to close the lid so that there is some airflow - not that it needs much - but it might if it gets hot again next summer.

Home Assistant UPS Mk2 Software Part 1

Determining the Battery State of Charge (SOC)#

Lead Acid Battery Voltage vs SOC

The voltage of a lead acid battery vs the SOC can be approximated to a straight line. This isn’t completely accurate especially at the extremes (0% and 100%) but it’s close enough. Especially given that batteries vary, the voltage can’t be measured 100% accurately and it’s a really bad idea to run a lead-acid battery down to 0% (which is about 10.5V). So the following equation gives quite a good approximation of the battery voltage (at rest):

Home Assistant UPS Mk2 Testing Part 2

When testing the charge circuit, something didn’t seem quite right…

HA UPS Mk2 Charging

The battery current was about 40mA even though the charging duty cycle was set to 3 (with a maximum of 255). A duty cycle of 3 should mean that the battery is charging for about 12us and not charging for the other 988us (the PWM should be running at 1kHz). If this was correct, it would mean that the current in the on phase was 3.4A (40mA * 255 / 3). Since the charging was via a 13Ω resistor, this seemed unlikely.

Home Assistant UPS Mk2 Testing Part 1a

Something I noticed when I connected and disconnected the USB serial port on the Arduino Nano was that the Nano would reset. After a bit of googling it turned out that this was caused by DTR on the CH340 serial chip being connected to the RESET pin (via a capacitor). So although I was powering the Nano from the UPS, when I shut down Home Assistant on the Raspberry Pi, HA would toggle DTR causing the Nano to reset.

Home Assistant UPS Mk2 Testing Part 1

This was my test setup:

HA UPS Mk2 Test Setup 1

The only thing I wasn’t testing was the Raspberry Pi voltage. This left input voltage and current and battery voltage and current, from which I could work out things like efficiency and estimated run time.

I had 4 lead acid batteries that I got from a radio club junk sale. Three were 4Ah and one was 800mAh. I tried that first. Under load the voltage dropped considerably. It was clear that the battery had degraded, so I decided not to use it.

Home Assistant UPS Mk II

I decided to have an uninterruptible power supply (UPS) for my Home Assistant (running on a Raspberry Pi). The design I came up with is shown below:

HA UPS Mk2 Block Diagram

The input from the mains is supplied by a 15V AC to DC adapter (wall wart). This is shown as Vcc/Vss on the diagram above. There are two DC to DC converters, one that powers the Raspberry Pi and one that powers an Arduino Nano. The rPi converter is a LM2596 and the Nano converter is a smaller device (which says it can deliver 3A but it only needs to deliver about 20mA).

Home Assistant Serial Link to an Arduino

The purpose of this project was to connect an Arduino Nano to the USB port that Home Assistant was running on. For me that is a Raspberry Pi 4 but this solution should work with any Home Assistant hardware. And the reason for using a serial connection over USB (rather than wirelessly with WiFi or similar) could be for many reasons:

  • Wifi may not be available (e.g. if the network is down)
  • It is more secure
  • It is un-jammable

The ultimate plan for me was to create an uninterruptable power supply for Home Assistant from bits that I had:

Arduino Low Power Encryption

LowPowerEncryptionBoard

This was my experiment in creating a low power Arduino that can communicate wirelessly to a Raspberry Pi using an HC-12. By low power I mean run for a couple of years on a 18650 battery. Encryption should be unhackable by today’s standards.

I did a presentation for the Raspberry Pint group, the video is here.

The code is on my Github repo. I had to do some mods to the Arduino board to make it low power (removing the regulator and power LED resistor):