The X728 uses two GPIO pins for a I2C interface to send the voltage and battery levels to the RPi and I want to read out these values directly into Domoticz, but can't find out how. I tried to use the I2C sensors hardware type in Domoticz, but this seems to be meant for other hardware.
Is there another way? There should be. The X728 board does come with a Python example for sending voltage and battery levels to the console, but I could not import that script (which runs fine when executed from the CLI) into the Domoticz script system because I immediately get an error in line 3, where it says: import smbus. This lib is installed on my system. Python finds it, but Domoticz doesn't.
And then there is the question about how to get the data into Domoticz variables. The Wiki is not clear on how to do this. Running the script outside of Domoticz and then sending a http request with the data over the internet could work, but really doesn't sound like an elegant solution for two devices that are physically connected to eachother. So what else could I try? I am not asking for a specific solution in Python, just some easy way to get the job done.
BTW the X728 example script is here:
Code: Select all
#!/usr/bin/env python
import struct
import smbus
import sys
import time
def readVoltage(bus):
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
voltage = swapped * 1.25 /1000/16
return voltage
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.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
while True:
print "******************"
print "Voltage:%5.2fV" % readVoltage(bus)
print "Battery:%5i%%" % readCapacity(bus)
if readCapacity(bus) == 100:
print "Battery FULL"
if readCapacity(bus) < 20:
print "Battery LOW"
print "******************"
time.sleep(2)