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)