Created
September 26, 2018 19:22
-
-
Save lauer/c70553a461d3cc0f3f804d5da3b4d9a9 to your computer and use it in GitHub Desktop.
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
{ | |
"wavin": [ | |
{ | |
"sensorid": 0, | |
"channelid": 0, | |
"location": "Bryggers" | |
}, | |
{ | |
"sensorid": 1, | |
"channelid": 1, | |
"location": "Entre" | |
}, | |
{ | |
"sensorid": 2, | |
"channelid": 2, | |
"location": "Kontor" | |
}, | |
{ | |
"sensorid": 3, | |
"channelid": 3, | |
"location": "Soveværelse" | |
}, | |
{ | |
"sensorid": 4, | |
"channelid": 4, | |
"location": "Bad 2" | |
}, | |
{ | |
"sensorid": 5, | |
"channelid": 5, | |
"location": "Stue" | |
}, | |
{ | |
"sensorid": 6, | |
"channelid": 7, | |
"location": "Køkkenalrum" | |
}, | |
{ | |
"sensorid": 7, | |
"channelid": 9, | |
"location": "Værelse 3" | |
}, | |
{ | |
"sensorid": 8, | |
"channelid": 10, | |
"location": "Værelse 2" | |
}, | |
{ | |
"sensorid": 9, | |
"channelid": 11, | |
"location": "Gang" | |
}, | |
{ | |
"sensorid": 10, | |
"channelid": 12, | |
"location": "Bad 1" | |
}, | |
{ | |
"sensorid": 11, | |
"channelid": 13, | |
"location": "Værelse 1" | |
} | |
] | |
} |
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/env python3 | |
from wavin_ahc9000_feature import * | |
from time import sleep | |
import json | |
import os | |
from pyzabbix import ZabbixMetric, ZabbixSender | |
wavin = WavinControl('/dev/ttyUSB0') | |
zabbix_server = 'xx' | |
zabbix_port = '10051' | |
host = 'xx' | |
# Config | |
configfile = os.path.join(os.path.dirname(__file__), 'config_wavin.json') | |
with open(configfile) as data_file: | |
config=json.load(data_file)['wavin'] | |
def send_packet(packet): | |
print(packet) | |
return ZabbixSender(zabbix_server).send(packet) | |
def get_setups(): | |
packet = [] | |
for x in config: | |
packet.append(ZabbixMetric(host, "wavin.room[%d,desired_temp]" %x['sensorid'], wavin.room(x['channelid']).desired_temperature)) | |
print(send_packet(packet)) | |
def get_channels(): | |
packet = [] | |
for x in config: | |
packet.append(ZabbixMetric(host, "wavin.channel[%d,current_consumption]" %x['sensorid'], wavin.channel(x['channelid']).current_consumption)) | |
print(send_packet(packet)) | |
def get_sensors(): | |
packet = [] | |
for x in config: | |
packet.append(ZabbixMetric(host, "wavin.sensor[%d,temp]" % x['sensorid'], wavin.sensor(x['sensorid']).temp_room)) | |
#sensor = wavin.sensor(x) | |
#room = wavin.room(x) | |
#print(x, sensor.temp_room, sensor.status, room.desired_temperature) | |
#print(x, sensor.temp_room) | |
print(packet) | |
result = send_packet(packet) | |
print(result) | |
def list_sensors(): | |
rooms = { | |
'data': [ | |
{ "{#SENSORID}":"0", "{#CHANNELID}":"0", "{#LOCATION}":"Bryggers"}, | |
{ "{#SENSORID}":"1", "{#CHANNELID}":"1", "{#LOCATION}":"Entre"}, | |
{ "{#SENSORID}":"2", "{#CHANNELID}":"2", "{#LOCATION}":"Kontor"}, | |
{ "{#SENSORID}":"3", "{#CHANNELID}":"3", "{#LOCATION}":"Soveværelse"}, | |
{ "{#SENSORID}":"4", "{#CHANNELID}":"4", "{#LOCATION}":"Bad 2"}, | |
{ "{#SENSORID}":"5", "{#CHANNELID}":"5", "{#LOCATION}":"Stue"}, | |
{ "{#SENSORID}":"6", "{#CHANNELID}":"0", "{#LOCATION}":"Køkkenalrum"}, | |
{ "{#SENSORID}":"7", "{#CHANNELID}":"0", "{#LOCATION}":"Værelse 3"}, | |
{ "{#SENSORID}":"8", "{#CHANNELID}":"0", "{#LOCATION}":"Værelse 2"}, | |
{ "{#SENSORID}":"9", "{#CHANNELID}":"0", "{#LOCATION}":"Gang"}, | |
{ "{#SENSORID}":"10", "{#CHANNELID}":"0", "{#LOCATION}":"Bad 1"}, | |
{ "{#SENSORID}":"11", "{#CHANNELID}":"0", "{#LOCATION}":"Værelse 1"} | |
] | |
} | |
packet = ZabbixMetric(host, 'wavin_sensors', rooms['data']) | |
print(send_packet([packet])) | |
print(json.dumps(rooms)) | |
if __name__ == "__main__": | |
import argparse | |
parser = argparse.ArgumentParser(description="Zabbix script for wavin") | |
parser.add_argument('-l', '--list', help = "Get list of all sensors", action='store_true') | |
parser.add_argument('-r', '--rooms', help = "Get room setups", action='store_true') | |
parser.add_argument('-s', '--sensors', help = "Get temperature of alle sensors", action='store_true') | |
parser.add_argument('-c', '--consumption', help = "Get current consumptions", action='store_true') | |
args = parser.parse_args() | |
if args.list == True: | |
list_sensors() | |
if args.sensors == True: | |
get_sensors() | |
if args.rooms == True: | |
get_setups() | |
if args.consumption == True: | |
get_channels() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment