Geekworm X728 UPS Hat for Raspberry pi over MQTT

Hi, I recently bought Geekworm X728 UPS HAT for my RPi running openhab. The software they provide is kind of samples not the ready to go solution. So, I decided to take my route and implement a service/daemon running on RPi to maintain all the aspects of it with the MQTT interface as I obviously wanted to integrate it with my Openhab.

If anyone would be interested you can find everything on my github repo: GitHub - marcinczeczko/x728-daemon: Python async daemon to drive Raspberry Pi Geekworm X728 UPS Hat

There are still couple of bits and pieces that I’d like to add but in general it does the job that can be summarized below:

  • Handling physical button on board to gracefully shutdown or reboot RPi
  • Monitor battery capacity and voltage and report it via MQTT
  • Send a warning via MQTT, if battery voltage is below certain value
  • Send a critical warning via MQTT, if battery drops below certain level
  • Gracefully shutdown RPi, if AC voltage is missing and critical warning about battery level were triggered
  • Send an alert via MQTT, if AC power is off
  • Finally, MQTT command topic to trigger gracefull reboot or shutdown of my RPi

If you don’t have x728 maybe it will help you implemented similar thing for your UPS.

Hope it will help someone.

PS. Here is my things and items definition I used to integrate with daemon

Thing mqtt:topic:oh-ups "MQTT - Openhab - UPS" (mqtt:broker:broker) [payloadNotAvailable="OFFLINE", payloadAvailable="ONLINE", availabilityTopic="home/tele/oh-ups/LWT"] {
    Channels:
        Type number : batteryVoltage "Battery Voltage" [stateTopic="home/stat/oh-ups/BATTERY", transformationPattern="JSONPATH:$.Voltage", unit="V"]
        Type number : batteryCapacity "Battery Capacity" [stateTopic="home/stat/oh-ups/BATTERY", transformationPattern="JSONPATH:$.Capacity", unit="%"]
        Type switch : ac "AC Power State" [ stateTopic="home/stat/oh-ups/ACPOWER", off="OFF", on="ON"]
        Type string : batteryAlarm "BatteryAlarm" [ stateTopic="home/alert/oh-ups/BATTERY"]
        Type string : shutdown "Shutdown Command" [ stateTopic="home/stat/oh-ups/SHUTDOWN", commandTopic="home/cmnd/oh-ups/SHUTDOWN", allowedStates="REBOOT,SHUTDOWN"] 
}

And items file

Number:ElectricPotential Openhab_UPS_Battery_Voltage "Openhab UPS - Battery Voltage [%s V]" <battery> { channel="mqtt:topic:oh-ups:batteryVoltage" }
Number:Dimensionless Openhab_UPS_Battery_Capacity "Openhab UPS - Battery level [%s %%]" <battery> { channel="mqtt:topic:oh-ups:batteryCapacity" }
Switch Openhab_UPS_AC_Power "Openhab UPS - AC Power" <switch> ["Switch"] {channel="mqtt:topic:oh-ups:ac"}
String Openhab_UPS_LowBattery "Openhab UPS - Battery alarm" <lowbattery> ["Alarm", "Energy"] {channel="mqtt:topic:oh-ups:batteryAlarm"}
String Openhab_UPS_Shutdown "Openhab UPS - Shutdown RPi" {channel="mqtt:topic:oh-ups:shutdown"}