Created
February 7, 2018 22:10
-
-
Save mohclips/3ff5367f4222322ee2940d003b2d8722 to your computer and use it in GitHub Desktop.
collectd plugin to read ownet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -u | |
from time import localtime, strftime | |
from pyownet import protocol | |
hostname="rpi-loft" | |
port=4304 | |
interval=60 | |
DEBUG=False | |
TIMEOUT=5 | |
sensors = ["CH_feed", "CH_return", "Hot_water", "Cold_water", "One", "Two"] | |
def get_RPI_owtemp(host, port): | |
try: | |
owproxy = protocol.proxy(host, port, verbose=DEBUG) | |
except protocol.ConnError as error: | |
print "Error: Unable to open connection to host:port" | |
return None | |
except protocol.ProtocolError as error: | |
print "Protocol error",error | |
return None | |
try: | |
owdir = owproxy.dir(slash=False, bus=False, timeout=TIMEOUT) | |
#print owdir | |
except protocol.OwnetError as error: | |
print "ownet error",error | |
return None | |
except protocol.ProtocolError as error: | |
print "Protocol error getting owdir",error | |
return None | |
sensor_data = {} | |
for sensor in owdir: | |
try: | |
stype = owproxy.read(sensor + '/type', timeout=TIMEOUT).decode() | |
if stype in [ 'DS18S20' , 'DS18B20' ]: | |
data = owproxy.read(sensor+'/temperature', timeout=TIMEOUT) | |
#print "read: %s %.1f" % ( sensor[1:], float(data) ) | |
sensor_data[ sensor[1:] ] = float(data) | |
except protocol.OwnetError as error: | |
print "ownet error",error | |
next | |
except protocol.ProtocolError as error: | |
print "Protocol error",error | |
next | |
return sensor_data | |
timestamp = strftime("%s", localtime()) | |
data=get_RPI_owtemp(hostname, port) | |
#print "data:",data | |
for sensor in sensors: | |
temperature = data[sensor] | |
print "PUTVAL \"%s/owfs_%s/temperature\" interval=%s %s:%s" % (hostname, sensor, interval, timestamp, temperature) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment