I installed a X725 UPS on my raspberry Pi and I wanted to monitor in Domoticz the voltage of the battery. The X725 provides some python scripts to retrieve measures using I2C tools (it does import smbus library in python).
I could modify the python script from vendor to update device value in domoticz:
Code: Select all
#!/usr/bin/env python
import struct
import smbus
import urllib
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
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
VOLTAGE_BATTERY = readVoltage(bus)
domoticz_V = "9999" # IDX for virtual sensor for voltage
httpresponse = urllib.urlopen("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=" + str(domoticz_V) + "&nvalue=0&svalue=" + str(float(VOLTAGE_BATTERY)))
Code: Select all
return {
on = {
timer = {
'every 3 minutes', -- causes the script to be called every 3 minutes
}
},
execute = function(domoticz, timer)
domoticz.log('Timer UPS_Battery event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
domoticz.utils.osExecute("/usr/bin/python /home/pi/domoticz/scripts/python/BatteryX725.py")
end
}- I don't use embedded Events module of domoticz for the python script..
- I use a url call to update domoticz
- my python script needs to be also updated in case I modify the IDX of device..
- and also I've the feeling that I use more CPU capability than I should.
So is there a better way to handle my need ?
Like using this python smbus library or equivalent directly in dzvents ?
or like dzvents retrieving directly the voltage value from the python script without the script having to call the URL ?
or even maybe using the Python script embedded in domoticz Events ? (but I couldn't find musch documentation on tht one, and I didn't understand how to trigger every X minutes and how to really update the device value..)
Thanks for your hints !
Ricorico94