diff --git a/CHANGELOG.md b/CHANGELOG.md index f684a41..96569e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### __[v2.5.2]__ - unreleased ##### Added +- fhemCmd-Plugin: New plugin fhemCmd to execute commands in FHEM home automation. [#457](https://github.com/Schrolli91/BOSWatch/pull/457) ##### Changed - Divera Plugin: Add individual alarms for FMS, ZVEI and POC. [#451](https://github.com/Schrolli91/BOSWatch/pull/451) - install.sh: local git repo available at /opt/boswatch (or at your own path). Updates easier with `git pull` in /opt/boswatch. [#452](https://github.com/Schrolli91/BOSWatch/pull/452) diff --git a/config/config.template.ini b/config/config.template.ini index 4c33f2a..8d2a9a4 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -182,6 +182,7 @@ yowsup = 0 hue = 0 Divera = 0 gpiocontrol = 0 +fhemCmd = 0 # for developing - template-module template = 0 @@ -525,6 +526,26 @@ triggertime = 180 #POC Rics that trigger PIN (empty: allow all, separator ",") activerics = 1234567,1234568 +[fhemCmd] +# choose one of "http", "https" or "telnet" +protocol = http + +# servername or IP address +server = 192.168.0.1 + +# numeric port +port = 8083 + +# username if required +username = dummyUser + +# password if required +password = dummyPassword + +# desired command to execute +commandFMS = set SteckdoseSchlafzimmerEinsatz on-for-timer 90 +commandZVEI = +commandPOC = ##################### ##### Not ready yet # diff --git a/plugins/fhemCmd/fhemCmd.py b/plugins/fhemCmd/fhemCmd.py new file mode 100644 index 0000000..2658e2e --- /dev/null +++ b/plugins/fhemCmd/fhemCmd.py @@ -0,0 +1,113 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" +Plugin for calling FHEM home automation + +@author: Marco Schotthöfer + +@requires: python-fhem (pip install fhem) +""" + +# +# Imports +# +import logging # Global logger +from includes import globalVars # Global variables + +# Helper function, uncomment to use +#from includes.helper import timeHandler +#from includes.helper import wildcardHandler +from includes.helper import configHandler +from includes.helper import wildcardHandler +import fhem + +## +# +# onLoad (init) function of plugin +# will be called one time by the pluginLoader on start +# +def onLoad(): + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin + + @requires: nothing + + @return: nothing + @exception: Exception if init has an fatal error so that the plugin couldn't work + + """ + try: + ########## User onLoad CODE ########## + pass + ########## User onLoad CODE ########## + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) + raise + +## +# +# Main function of plugin +# will be called by the alarmHandler +# +def run(typ,freq,data): + """ + This function is the implementation of the Plugin. + + If necessary the configuration hast to be set in the config.ini. + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see readme.md in plugin folder) + @param data: Contains the parameter for dispatch + @type freq: string + @keyword freq: frequency of the SDR Stick + + @requires: If necessary the configuration hast to be set in the config.ini. + + @return: nothing + @exception: nothing, make sure this function will never thrown an exception + """ + try: + if configHandler.checkConfig("fhemCmd"): #read and debug the config (let empty if no config used) + + protocol = globalVars.config.get("fhemCmd", "protocol") + logging.debug("protocol: %s", protocol) + + server = globalVars.config.get("fhemCmd", "server") + logging.debug("server: %s", server) + + port = globalVars.config.get("fhemCmd", "port") + logging.debug("port: %s", port) + + username = globalVars.config.get("fhemCmd", "username") + logging.debug("username: %s", username) + + password = globalVars.config.get("fhemCmd", "password") + logging.debug("password: %s", password) + + ########## User Plugin CODE ########## + if typ == "FMS": + fhemCommand = globalVars.config.get("fhemCmd", "commandFMS") + elif typ == "ZVEI": + fhemCommand = globalVars.config.get("fhemCmd", "commandZVEI") + elif typ == "POC": + fhemCommand = globalVars.config.get("fhemCmd", "commandPOC") + else: + logging.warning("Invalid Typ: %s", typ) + return False + + fhemCommand = wildcardHandler.replaceWildcards(fhemCommand, data) + logging.debug("fhemCommand: %s", fhemCommand) + + fh = fhem.Fhem(server=server, protocol=protocol, port=port, username=username, password=password) + + fh.send_cmd(fhemCommand) + del fh + ########## User Plugin CODE ########## + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) diff --git a/plugins/fhemCmd/requirements.txt b/plugins/fhemCmd/requirements.txt new file mode 100644 index 0000000..a852eb5 --- /dev/null +++ b/plugins/fhemCmd/requirements.txt @@ -0,0 +1 @@ +fhem