I've been fighting with this thing for a minute. At first I had a charger on a timer and that worked, but not very good on the batteries. Then in Home Assistant I used it as a timer. Which was exactly the same thing.

Then I took it a step further. I'll list the parts first.

  • a 5X voltage divider (found here)
  • a ADS1115 ADC (found here)
  • a zigbee outlet and zigbee hub if you don't already have one.
  • and a Raspberry PI (any will work)

Software needed

  • Any flavor of linux distro
  • Python
  • Adafruit CircuitPython
  • Paho-mqtt
  • Home Assistant on VM or dedicated machine to make this all work. 

Making all that work is the trick. On the sixth install everything started working correctly. No idea what I did. Installed raspbian, then adafruit and then paho-mqtt.

The Python code for the PI looks like this.

------------------------------>8------------------------------
import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from paho.mqtt import client as paho

broker = '10.0.2.22' #your mqtt server here
port = 1883
topic = 'pi/event/voltage'

def on_publish(client,userdata,result):             #create function for callback
    print("data published \n")
    pass
client1= paho.Client("control1")                    #create client object
client1.on_publish = on_publish                     #assign function to callback
client1.connect(broker,port)                        #establish connection

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)

# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)

while True:
    print(round(chan.voltage*5,2))
    ret= client1.publish(topic,float(round(chan.voltage*5,2)))
    time.sleep(10)
------------------------------>8------------------------------

float probably isn't nessisary, but I was fighting so many things before I realized I had an "s" in event on the configuration.yaml.

In home assistant you have to define the mqtt entry in the configuration.yaml.

------------------------------>8------------------------------
mqtt:
  sensor:
  - name: "PI Voltage"
      state_topic: "pi/event/voltage"

------------------------------>8------------------------------

At this point you create the automation to watch the numeric state of "PI Voltage". I have two. One to turn on below 12V and one to turn off above 14.8V. I could do it as one automation, but brain doesn't do big brain stuff without coffee and sleep. And I had been pulling cameras and com speakers in the sun all day getting ready for demo. Not my normal job, but last time I sourced it out everything was destroyed by idiotic workers just ripping things off of beams and walls. So I had to use the BIG BRAIN stuff. Squeeze RJ45 connector and unplug device. X screwdriver fits X shaped hole and turn counter clockwise and wires fall off. Not "BIGGEST HAMMER FIX EVERYTHING" or "HULK SMASH". Also plastic bags are good for keeping devices seperated. Not "THROW ALL SURVIVING PIECES IN ONE BOX"