motom001 / DoorPi

OpenSource VoIP Door-Intercomstation
https://www.doorpi.org/forum/
238 stars 85 forks source link

Telefonnummern richten sich nach Anwesenheit #32

Closed motom001 closed 9 years ago

motom001 commented 9 years ago

Wünsche von hier: http://www.ip-symcon.de/forum/threads/26739-DoorPI-VoIP-Door-Intercomstation-with-Raspberry-Pi?p=245497#post245497

Meine Wünsche wären ...

V1. Ist wer zu Hause = Haustelefon und Videostream auf dem Monitor V2. ist keiner zu Hause = Videostream auf dem Handy

VG

Andreas

hermanthegerman2 commented 9 years ago

Da die Anforderung aus dem IP-Symcon Lager kommt evtl. über die JSON API Get eine oder mehrere Anwesenheits Variablen auslesen. In dieser steht idealerweise schon die Nummer, welche angerufen werden soll. Evtl über die Timeticks zyklisch auslesen lassen, falls in der doorpi.cfg angegeben. Würde das funktionieren Thomas?

motom001 commented 9 years ago

Hab meine Antwort dort noch nicht einmal gepostet, da geht es hier schon weiter - Wahnsinn... Natürlich ist es per API möglich eine Variable auszulesen und:

Mir gefällt die erste Lösung besser, da es dann eine Rückfallebene gibt, wenn das IP-Symcon nicht verfügbar wäre.

Das zyklische auslesen ist auch eine Möglichkeit. Allerdings belastet das die Systeme (unnötig) und ist ggf. ungenau. Zu hohe Belastung wenn es im Sekundentakt ausgelesen wird, zu ungenau, wenn es im Tagesrythmus ausgelesen wird.

Irgendwo ist ein gesunder Mittelweg und dafür wäre es interessant, wie bisher Anwesenheit symbolisiert wird. Wo wird wann und wie welches Bit gesetzt?

hermanthegerman2 commented 9 years ago

Viele setzen über die Anwesenheit des Handy´s (banal, oder?) die Anwesenheitsvariable. Diese alle 2-5min auszulesen würde IMHO die Systeme nicht belasten und ausreichend genau sein.

motom001 commented 9 years ago

@hermanthegerman2: Bitte mal testen :)

hermanthegerman2 commented 9 years ago

hast eine PM. Sieht aber schon mal sehr gut aus. Hattest übrigens Recht, dass simplejson nicht unbedingt benötigt wird. Habe es heute nochmal getestet!

hermanthegerman2 commented 9 years ago

Zwischenstand: IPS_Variable wird geholt, make_call macht Probleme! benötige Hilfe

motom001 commented 9 years ago

Heute Abend im IRC an bekannter Stelle?

hermanthegerman2 commented 9 years ago

abgemacht!

wuppi83 commented 9 years ago

Moin,

leider klappt das Script von hermanthegerman2 nicht mehr. Hast du ne Idee woran das liegen könnte?

wuppi83 commented 9 years ago

´´´

!/usr/bin/env python

-- coding: utf-8 --

import logging logger = logging.getLogger(name) logger.debug("%s loaded", name)

import doorpi import requests import json from requests.auth import HTTPBasicAuth from action.base import SingleAction

def ips_rpc_create_config(): config = {} config['webservice_url'] = doorpi.DoorPi().config.get('IP-Symcon', 'server') config['username'] = doorpi.DoorPi().config.get('IP-Symcon', 'username') config['password'] = doorpi.DoorPi().config.get('IP-Symcon', 'password') config['jsonrpc'] = doorpi.DoorPi().config.get('IP-Symcon', 'jsonrpc', '2.0') config['headers'] = {'content-type': 'application/json'} return config

def ips_rpc_fire(method, config, *parameters): payload = { "method": method, "params": parameters, "jsonrpc": config['jsonrpc'], "id": 0, } return requests.post( config['webservice_url'], headers = config['headers'], auth = HTTPBasicAuth(config['username'], config['password']), data = json.dumps(payload) )

def ips_rpc_check_variable_exists(key, config = None): if config is None: config = ips_rpc_create_config() response = ips_rpc_fire('IPS_VariableExists', config, key) logging.debug("IPS_VariableExists: %s", response.json['result']) return response.json['result']

def ips_rpc_get_variable_type(key, config = None): if config is None: config = ips_rpc_create_config() response = ips_rpc_fire('IPS_GetVariable', config, key) logging.debug("IPS_GetVariable: %s", response.json['result']) return response.json['result']['VariableValue']['ValueType']

def ips_rpc_get_variable_value(key, config = None): if config is None: config = ips_rpc_create_config() response = ips_rpc_fire('GetValue', config, key) logging.debug("IPS_GetValue: %s", response.json['result']) return response.json['result']

def ips_rpc_call_phonenumber_from_variable(key, config = None): try: if config is None: config = ips_rpc_create_config() if ips_rpc_check_variable_exists(key, config) is not True: raise Exception("var %s doesn't exist", key) type = ips_rpc_get_variable_type(key, config) if type is None: raise Exception("type of var %s couldn't find", key)

http://www.ip-symcon.de/service/dokumentation/befehlsreferenz/variablenverwaltung/ips-getvariable/

    # Variablentyp (0: Boolean, 1: Integer, 2: Float, 3: String)
    elif type is not 3: raise Exception("phonenumber from var %s is not a string", key)
    phonenumber = ips_rpc_get_variable_value(key, config)
logging.debug(phonenumber)
    from action.SingleActions.call import make_call
    make_call(phonenumber)

except Exception as ex:
    logger.exception("couldn't get phonenumber from IpsRpc (%s)", ex)
    return False
return True

def get(parameters): parameter_list = parameters.split(',') if len(parameter_list) is not 1: return None

key = int(parameter_list[0])

return IpsRpcCallPhonenumberFromVariableAction(ips_rpc_call_phonenumber_from_variable, key)

class IpsRpcCallPhonenumberFromVariableAction(SingleAction): pass ´´´