Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Check https://www.hjemmeautomasjon.no/forums/topic/2737-multireg-termostat-se-n%C3%A5r-den-er-%C2%ABaktiv%C2%BB-i-homeseer/?tab=comments#comment-33740
- import os, sys
- import time
- import openhab
- openhab_url = 'http://foobar:8090/rest'
- openhab_client = openhab.openHAB(openhab_url)
- openhab_logfile = '/var/log/openhab2/openhab.log'
- multiregs = {
- # z-wave node, room name
- '22': 'Rom1',
- '23': 'Rom2',
- '11': 'Rom3',
- '14': 'Rom4'
- }
- #
- # Tail a logfile that can be rotated at any time:
- def tail(theFile, filename, inode):
- theFile.seek(0,2) # Go to the end of the file
- while True:
- line = theFile.readline()
- if not line:
- time.sleep(2) # Sleep briefly for 10sec
- if os.stat(filename).st_ino != inode:
- # Wait for new file:
- while not os.path.isfile(filename):
- time.sleep(1)
- theFile = open(filename, 'r')
- inode = os.stat(filename).st_ino
- print "LOGFILE ROTATED"
- continue
- yield line
- if __name__ == '__main__':
- linecounter = 0
- lastbasicset = 0
- fd = open(openhab_logfile, 'r')
- current_inode = os.fstat(fd.fileno()).st_ino
- for line in tail(fd, openhab_logfile, current_inode):
- linecounter += 1
- if line.find('NODE') > 0 and line.find('Basic Set sent to the controller') > 0:
- lastbasicset = linecounter
- if line.find('NODE') > 0 and line.find('Basic report') > 0 and linecounter < lastbasicset + 4:
- elements = line[line.find('NODE'):].split()
- nodeno = elements[1].replace(':', '')
- if nodeno in multiregs and elements[6] == "0x00":
- print multiregs[nodeno] + " was turned off"
- openhab_client.get_item('Termostat_' + multiregs[nodeno] + "_bryter").state = "OFF"
- elif nodeno in multiregs and elements[6] == "0xFF":
- print multiregs[nodeno] + " was turned ON"
- openhab_client.get_item('Termostat_' + multiregs[nodeno] + "_bryter").state = "ON"
- else:
- print "Not multireg node:"
- print elements
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement