Integrating UPS Hat with Raspberry Pi Zero W for Security Camera

Hi all,

I’m reaching out to seek some guidance on integrating a UPS hat with my Raspberry Pi Zero W setup for my security camera. I’m relatively new to coding, so I appreciate your patience and expertise in advance.

Currently, I have a Raspberry Pi Zero W running a security camera via MotionEye on Raspbian Buster Lite. To enhance its security functionality, I’ve added a UPS hat (this one) which includes a Python script available on their GitHub page. This script successfully measures the battery level, and the battery lasts approximately 10 minutes with the camera attached. However, I would like to take this a step further by integrating this functionality into my Home Assistant (HA) instance to enable an automatic shutdown when the battery is low.

My question is, how can I achieve this? I understand that setting up a cron job to run the script is a feasible approach, but I’m unsure about how to import the battery data into HA. MQTT seems like a potential solution, but I’m not familiar with how to implement this within the code. Additionally, I’m curious about how Glances works and whether I can leverage it to piggyback on the battery information.

Any assistance or guidance would be greatly appreciated! I’m currently running hassOS on a Raspberry Pi 4B 8GB.

Thank you in advance for your help!

Best regards,
Bob