Moin,
anbei ein Plug-In, um meine Gasbrennwert-Therme mittels Siemens OZW auszulesen.
Sowie eine kurze Beschreibung:
Bei mir ist dieses Plug-In lauffähig - elegantes Python sieht jedoch bestimmt anders aus ;-)
Wer möchte kann gerne unterstützen, bzw. den Code-Schnipsel in GitHub übernehmen.
anbei ein Plug-In, um meine Gasbrennwert-Therme mittels Siemens OZW auszulesen.
Code:
#!/usr/bin/env python3 ################################################## ####################### # Copyright 2015 KNX-Username : KHome # Quick-Dirty Solution with CURL / JQ ################################################## ####################### # Free for non-commercial use ################################################## ####################### # to install jq follow: # https://stedolan.github.io/jq/download/ ################################################## ####################### import logging import subprocess import time logger = logging.getLogger('SiemensOZW') class SiemensOZW(): _items = [] def __init__(self, smarthome, host='192.168.178.178', username=None, password=None, cycle=60): self._sh = smarthome self._ozwhost = host self._username = username self._password = password self._sid = 0 self._cycle = int(cycle) self.refresh_cycle = self._cycle def run(self): logging.warning("SiemensOZW is running") self.alive = True self._sh.scheduler.add('ozwcycle', self.refresh, prio=5, cycle=self._cycle, offset=2) def stop(self): self.alive = False def parse_item(self, item): if 'ozw_nr' in item.conf: self._items.append(item) return self.update_item def update_item(self, item, caller=None, source=None, dest=None): #logging.warning("update function") if caller != 'SiemensOZW': #logger.info("update item: {0}".format(item.id())) value = str(int(item())) def refresh(self): #logging.warning("refresh function") for item in self._items: time.sleep(1) ozw_variable = item.conf['ozw_nr'] value = self.request(ozw_variable) #logging.warning(ozw_variable) #logging.warning(value) #if reading fails (i.e. at broadcast-commands) the value will not be updated if value is not None: item(value, 'SiemensOZW', 'refresh') if not self.alive: break def request(self, request): #logging.warning("request function") try: uri = "http://" + self._ozwhost + "/api/auth/login.json?user=" + self._username + "&pwd=" + self._password proc = subprocess.Popen('curl -k -sb -H \"Accept: application/json\" \"' + uri + '\" | jq \'.SessionId\'', stdout=subprocess.PIPE, shell=True) (out, err) = proc.communicate() out = str(out,"utf-8") outnew = out.replace('\"', '') self._sid = outnew.replace('\n', '') logger.debug("sid = {0}".format(self._sid)) if self._sid == '0': logger.warning("SiemensOZW: invalid sid, none received ") uri_readpoint = "http://" + self._ozwhost + "/api/menutree/read_datapoint.json?SessionId=" + self._sid + "&Id=" idnr = request #867 cmdt = 'curl -k -sb -H \"Accept: application/json\" \"'+ uri_readpoint + str(idnr) + '\" | jq \'.Data.Value\'' proc = subprocess.Popen(cmdt, stdout=subprocess.PIPE, shell=True) (out2, err2) = proc.communicate() #print("program output:", out2) out2 = str(out2,"utf-8") answer = out2.replace('\"', '') #not all values are float; it could be also: "Ein" return answer except: logger.warning("Unexpected error: SiemensOZW some execution read error")
Code:
# SiemensOZW ## Requirements/Description Description: Connects to read-only Siemens OZW672 over LAN Requirements-SW: CURL and JQ ## Supported Hardware www.siemens.com/download?A6V10336376 I.e. Siemens OZW672 (some configurations needed to access - via http (not https) - data via LAN - Username & data regarding security level (not all data are visible for each profile) ## Configuration ### plugin.conf [ozw] class_name = SiemensOZW class_path = plugins.ozw host = localhost # ip of ebusd cycle = 30 # cycle of each item username = 'user' password = 'pass' ### items.conf Items need parameter "ozw_nr" [ozw] [[temperatur_outside]] type = num knx_dpt = 5 knx_send = 15/1/0 knx_reply = 15/1/0 ozw_nr = "788"
Wer möchte kann gerne unterstützen, bzw. den Code-Schnipsel in GitHub übernehmen.
Kommentar