Last active
March 25, 2017 11:36
-
-
Save tchellomello/bb310ca30a0fd2e5ddacc0321599d353 to your computer and use it in GitHub Desktop.
Script to monitor Open Zwave events for ZRC90 scene control
This file contains 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/env python3 | |
import socket | |
import requests | |
from subprocess import Popen, PIPE | |
import json | |
## line which as Node004 ZRC-90 command | |
# scene1 | |
#2017-01-14 23:36:31.244 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x66, 0x00, 0x01, 0xce | |
# scene2 | |
#2017-01-14 23:37:10.186 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x67, 0x00, 0x02, 0xcc | |
# scene3 | |
#2017-01-14 23:38:08.028 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x68, 0x00, 0x03, 0xc2 | |
# scene4 | |
#2017-01-14 23:38:37.856 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x69, 0x00, 0x04, 0xc4 | |
# scene5 | |
#2017-01-14 23:39:00.205 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x6a, 0x00, 0x05, 0xc6 | |
# scene6 | |
#2017-01-14 23:40:09.976 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x6b, 0x00, 0x06, 0xc4 | |
# scene7 | |
#2017-01-14 23:41:09.002 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x6c, 0x00, 0x07, 0xc2 | |
# scene8 | |
#2017-01-14 23:41:36.684 Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03, 0x6e, 0x00, 0x08, 0xcf | |
# match rule | |
MATCHER = 'Detail, Node004, Received: 0x01, 0x0b, 0x00, 0x04, 0x00, 0x04, 0x05, 0x5b, 0x03,' | |
if socket.gethostname() == 'pi.home': | |
OZW_LOG = '/home/hass/.homeassistant/OZW_Log.txt' | |
else: | |
OZW_LOG = '/tmp/OZW_Log.txt' | |
# HA information | |
URI = 'http://127.0.0.1:8123/api/services/script/turn_on' | |
TOKEN = 'secret' | |
debug = False | |
log = Popen(('/usr/bin/tail', '-F', '-n', '0', OZW_LOG), stdout=PIPE) | |
while True: | |
line = log.stdout.readline() | |
if not line: | |
break | |
line = line.strip().decode('utf-8') | |
# Fast match to discard non-info log messages | |
if MATCHER not in line: | |
continue | |
button = line.split(',')[-2].replace(' 0x0','') | |
event = 'script.zrc90_a_button_{0}'.format(button) | |
if debug: | |
print(event) | |
if event: | |
data = {'entity_id': event} | |
if debug: | |
print(data) | |
resp = requests.post(URI, data=json.dumps(data), headers={'x-ha-access': TOKEN, 'content-type': 'application/json'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SystemD service