What’s your board (Pi HAT)? Maybe this is the case when the algorithm is not compatible with x720.
I have a Pi4 64bit
And the UPS hat model?
EP-0118! It has to work… The question is how
Is this another manufacturer (not Geekworm)?
I understand that’s 52Pi. Their website has a different code for getting battery data. The component I sent will not work. It gets the data using a different algorithm.
Do you think it could work for x725?
Yes, I think so.
Hi,
if somebody interested I’ve made it work for X708, but different approach using original scripts with altered, pure python smbus2 library.
Tested on HA dev 5.2 64 bit (needed for autoboot from SSD, X857 HAT)
Prereq:
- I2C enabled
- Installed smbus2, from ssh console: pip install smbus2
- 2 scripts: readvoltage.py and readcapacity.py put in in /share folder
configuration:
binary_sensor:
- platform: rpi_gpio
invert_logic: true
ports:
6: UPSStatus
sensor:
- platform: command_line
name: UPSBatteryVoltage
unit_of_measurement: "V"
command: python3 /share/readvoltage.py
- platform: command_line
name: UPSBatteryCapacity
unit_of_measurement: "%"
command: python3 /share/readcapacity.py
readvoltage.py:
import struct
import sys
import time
from smbus2 import SMBus
def readVoltage(bus):
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
voltage = swapped * 1.23 /1000/16
return voltage
bus = SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
print ("%5.2f" % readVoltage(bus))
readcapacity.py:
import struct
import sys
import time
from smbus2 import SMBus
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
return capacity
bus = SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
print ("%5.2f" % readCapacity(bus))
Result (charging ongoing, changed voltage factor from original 1.25 to 1.23 based on multi-meter values to match)
Ooooo, I am hoping this works. I have the X728 from Geekworm. Will give this a try.
I’m able to access the entities for capacity, voltage and status of the Geekworm X708 UPS.
Thanks @rasterer for for providing his instructions and scripts here: https://community.home-assistant.io/t/greekworm-ups-hat/53059/28
My setup:
- Raspberry Pi 4
- Geekworm X708 UPS
- Home Assistant OS (Hass.io) for Raspberry Pi 4 Model B 64-bit
What I did:
- Enabled I2C as described here: https://www.home-assistant.io/hassio/enable_i2c/
- Activated the advanced mode: Home Assistant > User > Advanced Mode
- Installed the SSH & Web Terminal add-on: Home Assistant > Supervisor > Add-on Store
- Installed smbus2 in the terminal: pip install smbus2
- Created the files /share/readvoltage.py and /share/readcapacity.py provided by @rasterer.
- Installed the File editor add-on: Home Assistant > Supervisor > Add-on Store
- Added the configuration to the configuration.yaml file as defined by @rasterer.
- Rebooted the Raspberry Pi 4 and the entities UPSBatteryCapacity, UPSBatteryVoltage and UPSStatus where listed and working.
Now it’ll be nice to know how to cleanly shutdown Home Assistant if the UPS sends the according signal. I’m sure it’s possible.
Hi Beduir.
I’m too NOOB and I’m asking for help if you have a time for it…
So…
Hardware:
1.Raspberry Pi 3B
2.Geekworm X750 - https://raspberrypiwiki.com/X750
Software:
Home Assistant OS 5.11
- I’ve editted sensor.py file and replaced all “x720” letters with “x750”.
- Added files to custom_components directory.
- Editted configuration.yaml file and added
sensor:- platform: x750
name: ‘RPi Battery’
- platform: x750
to the sensor section.
Edited and manifest.json file with the right address for Geekworm X750 section.
Made automations for notifying at 95% and shutdown at 35% (because the shutdown time is enough long - approximately 10 minutes; sometime longer…)
And everything with voltage and capacity is working.
But x750’s button isn’t working.
Is there a way to implement X750 software at https://raspberrypiwiki.com/X750
Added sudo trough SSH console.
But when I start the script the answer from the script is that there is no such file or directory for /etc/rc.local and for /home/pi/.
I’m trying to make implementation and because x750 is working after the RPi is shut downed from the automation ( I suppose there is no command from the Pi to switch off.)
Can you give me some advice, please?
Thank you in forward for time and support.
- I’ve editted sensor.py file and replaced all “x720” letters with “x750”.
There was no need for that. It would work without changes.
Can you give me some advice, please?
Unfortunately, I don’t know if this is possible in HassOS.
Hi again.
Anyway thanks for the time!
Will keep searching and trying.
Hi! I tried your guide. It’s awsome, but i have some problems with reading values from batteries.
I’m running Home Assistant OS 5.13 64 bit on Rpi 4 / 4GB.
I2C is enabled.
smbus2 is probably installed ( i inserted rasbian and wrote down comand: pip install smbus2 - removed sd card plugged in ssd and turned on HA).
I pasted config into configuration.yaml and created two scripts (pasted into /share folder).
It is showing only UPSStatus /on/off.
Thanks for reply.
Vit
I did the same but I’m not able to get capacity and voltage from batteries.
How can I solve it? Could be caused by the batteries type? I’m using geekworm U100 module with 18650 batteries.
Thanks in advance
Hello,
Just a quicky. Was someone able to find a case for both the RPI and X708 that fits ?
Regards,
Jens
Were you able to get it to work ? And which case are you using ?
Hi!
Yes it was working quite well. The only problem that I have was when restarting HA(not host; for example when making some HACS update) - the system loose the smbus communication and I have to restart the host to start working again (but I’m with RPi3B not RPi4). Maybe this is the problem.
I’m talking in past tense, because my Pi’s GPIO3 (SCL) port stop working(have tested - it’s not giving 3.3V anymore) and HA cannot communicate via smbus anymore. Have googling and there are written some ways to exchange the smbus port, but in my case I have to make totally new connector for X750(I’m with this UPS). And maybe is much better to buy new RPI3B.
For the case…
At AliExpress there are some cases wich can take X708 and RPI together. But you have to search exactly for your model of RPi and there are some limitations for some other plates.
There is my case but is DIY myself…
It cost me about 1 month to make it, because I have no 3D printer and every wall of the box was hand made (from this box)
Anyway there are cases wich can handle X708 and RPi together, but not with mSATA module like in my configuration.
With hot (41C°) greeting from Bulgaria: Dik
- BGN 150.41 10%OFF | For Raspberry Pi 4, X857 V2.0 mSATA SSD Shield + X708 UPS & Power Mgnt Board + X857-C3 Case with Power Switch & Cooling Fan
https://a.aliexpress.com/_msRNlBV - BGN 175.40 | Raspberry Pi 4B X873 V1.2 NVMe M.2 SSD Shield + X708 V1.2 UPS & Power Management Board + Matching Metal kit
https://a.aliexpress.com/_mqpiPuX - BGN 42.15 9%OFF | Geekworm Raspberry Pi X857-C3 Case for Raspberry Pi 4 & X857 V2.0/ X862 V2.0 & X735/ X708, X857-C3 Matching Case + Switch + Fan
https://a.aliexpress.com/_mMuwQwP