Ankündigung

Einklappen
Keine Ankündigung bisher.

Plugin Google Home, Assistant und Status Sprachausgabe

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Plugin Google Home, Assistant und Status Sprachausgabe

    Hallo,

    ich habe grosses Interrese an Google Home, welcher nächsten Monat bei uns auf den Markt kommen soll und würde ihn gerne auf Smarthome NG einsetzten.
    Das ganze läuft ähnlich wie das Speech Plugin und benötigt folgende Apps:

    - Tasker
    - Auto Voice
    - Join
    - IFTTT
    - Ein Konto bei htps://api.ai

    Als Sprache wäre das Speech Plugin weiterhin nutzbar, allerdings wäre es jetzt ein wenig oversized. Die Antworten sowie die Keywords werden bei api.ai hinterlegt, da dieser auf Asisstant Antwortet.
    Um das System mit einem eigenen Keyword ansprechen zu können, brauchen wir IFTTT. Das ganze sieht dann so aus z.B "Ok Google" "2. Keyword" "Befehl". Das zur Spracheingabe!

    Zur Sprachausgabe ist die App Join und Tasker. Ähnlich wie bei Notify my Android oder andere kann man hier eine Message senden, die der Tasker wiederum in Sprache ausgibt. Ausgewählt werden können bestimmte Geräte wie bei Pushbullet.

    Möglich mit Join: Handy zum suchen Klingeln lassen, SMS, Url senden, File senden uvm.

    Diesen Teil habe ich bis zum Plugin stehen, woran es im Moment bei mir hängt. (Es ist mein 1. Plugin)

    Ich habe:

    Code:
    # Url Format: https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?title=<TITLE> Nachricht&icon=http://www.smartvisu.de/data/smartvisu_l.png&text==:=<MESSAGE> text=:=etc&url=<ADRESSSENDER>&clipboard=Some+Text& file=http://publicurl.com/image.jpg,http://publicurl.com/image2.jpg&deviceId=<DEVICEID>&apikey=<APIKEY>
    
    #[Join]
    # class_name = Join
    # class_path = plugins.Join
    # deviceid = <your-default-device-id>
    # apikey = <your-api-key>

    Code:
    import requests
    import logging
    from lib.model.smartplugin import SmartPlugin
    
    logger = logging.getLogger('Join')
    
    class Join(SmartPlugin):
    SEND_URL = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey="
    PLUGIN_VERSION = "1.0"
    ALLOW_MULTIINSTANCE = False
    
    
    def __init__(self, smarthome, apikey=None, deviceid=None, debug=False):
    logging.getLogger("requests").setLevel(logging.WAR NING)
    self.api_key = apikey
    self._deviceId = deviceid
    self._sh = sh
    self._debug = debug
    self.logger = logging.getLogger(Join)
    
    
    def run(self):
    self.alive = True
    
    def stop(self):
    self.alive = False
    
    
    def get_devices(api_key):
    response = requests.get(LIST_URL + api_key).json()
    if response.get('success') and not response.get('userAuthError'):
    return [(r['deviceName'], r['deviceId']) for r in response['records']]
    return False
    
    def send_notification(api_key, text, device_id=None, device_ids=None, device_names=None, title=None, icon=None, smallicon=None, vibration=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&text=" + text
    if title: req_url += "&title=" + title
    if icon: req_url += "&icon=" + icon
    if smallicon: req_url += "&smallicon=" + smallicon
    if vibration: req_url += "&vibration=" + vibration
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    
    def ring_device(api_key, device_id=None, device_ids=None, device_names=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&find=true"
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    
    def send_url(api_key, url, device_id=None, device_ids=None, device_names=None, title=None, text=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&url=" + url
    if title: req_url += "&title=" + title
    req_url += "&text=" + text if text else "&text="
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    
    def set_wallpaper(api_key, url, device_id=None, device_ids=None, device_names=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&wallpaper=" + url
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    
    def send_file(api_key, url, device_id=None, device_ids=None, device_names=None, title=None, text=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&file=" + url
    if title: req_url += "&title=" + title
    req_url += "&text=" + text if text else "&text="
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    
    def send_sms(api_key, sms_number, sms_text, device_id=None, device_ids=None, device_names=None):
    if device_id is None and device_ids is None and device_names is None: return False
    req_url = SEND_URL + api_key + "&smsnumber=" + sms_number + "&smstext=" + sms_text
    if device_id: req_url += "&deviceId=" + device_id
    if device_ids: req_url += "&deviceIds=" + device_ids
    if device_names: req_url += "&deviceNames=" + device_names
    requests.get(req_url)
    Fehler:
    Code:
    2017-07-11 15:49:03 ERROR Main Plugin Join exception: unindent does not match any outer indentation level (__init__.py, line 56)
    Traceback (most recent call last):
    File "/usr/local/smarthome/lib/plugin.py", line 90, in __init__
    plugin_thread = PluginWrapper(smarthome, plugin, classname, classpath, args, instance)
    File "/usr/local/smarthome/lib/plugin.py", line 127, in __init__
    exec("import {0}".format(classpath))
    File "<string>", line 1, in <module>
    File "/usr/local/smarthome/plugins/Join/__init__.py", line 56
    def run(self):
    ^
    IndentationError: unindent does not match any outer indentation level
    Worin liegt der Fehler?


    Viele Grüsse
    KNX Fan
    Zuletzt geändert von bmx; 11.08.2017, 07:14. Grund: [CODE] ... [/CODE] ergänzt zur leichteren Nachvollziehbarkeit

    #2
    leider postest du nicht als CODE Block. Deine Einrückungen scheinen aber nicht zu passen.

    Kommentar


      #3
      Oh, mir gar nicht aufgefallen

      Code:
      import requests
      import logging
      from lib.model.smartplugin import SmartPlugin
      
      class Join(SmartPlugin):
          SEND_URL = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey="
          LIST_URL = "https://joinjoaomgcd.appspot.com/_ah/api/registration/v1/listDevices?apikey="
          PLUGIN_VERSION = "1.0"
          ALLOW_MULTIINSTANCE = False
      
          def __init__(self, smarthome, api_key=None, device_id=None, debug=True):
              logging.getLogger("requests").setLevel(logging.WARNING)
              self._api_key = api_key
              self._device_id = device_id
              self._sh = smarthome
              self._debug = debug
              self.logger = logging.getLogger(__name__)
      
          def run(self):
              self.alive = True
      
          def stop(self):
              self.alive = False
      
      
          def get_devices(self,api_key):
              response = requests.get(LIST_URL + api_key).json()
              if response.get('success') and not response.get('userAuthError'):
                      return [(r['deviceName'], r['deviceId']) for r in response['records']]
              return False
      
          def send_notification(self, api_key, text, device_id=None, device_ids=None, device_names=None, title=None, icon=None, smallicon=None, vibration=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&text=" + text
              if title: req_url += "&title=" + title
              if icon: req_url += "&icon=" + icon
              if smallicon: req_url += "&smallicon=" + smallicon
              if vibration: req_url += "&vibration=" + vibration
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      
          def ring_device(self, api_key, device_id=None, device_ids=None, device_names=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&find=true"
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      
          def send_url(self, api_key, url, device_id=None, device_ids=None, device_names=None, title=None, text=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&url=" + url
              if title: req_url += "&title=" + title
              req_url += "&text=" + text if text else "&text="
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      
          def set_wallpaper(self, api_key, url, device_id=None, device_ids=None, device_names=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&wallpaper=" + url
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      
          def send_file(self, api_key, url, device_id=None, device_ids=None, device_names=None, title=None, text=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&file=" + url
              if title: req_url += "&title=" + title
              req_url += "&text=" + text if text else "&text="
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      
          def send_sms(self, api_key, sms_number, sms_text, device_id=None, device_ids=None, device_names=None):
              if device_id is None and device_ids is None and device_names is None: return False
              req_url = SEND_URL + api_key + "&smsnumber=" + sms_number + "&smstext=" + sms_text
              if device_id: req_url += "&deviceId=" + device_id
              if device_ids: req_url += "&deviceIds=" + device_ids
              if device_names: req_url += "&deviceNames=" + device_names
              requests.get(req_url)
      in plugin.conf:
      Code:
      [Join]
          class_name = Join
          class_path = plugins.Join
          deviceid = <your-default-device-id>
          apikey = <your-api-key>
      Zuletzt geändert von Knx fan; 11.07.2017, 18:05.

      Kommentar


        #4
        Bis auf run() und stop() fehlt allen Methoden das self in der Definition.
        Viele Grüße
        Martin

        There is no cloud. It's only someone else's computer.

        Kommentar


          #5
          Danke! Hab den Code oben geändert. Jetzt läuft es ohne Fehler, allerdings klappt die Logik noch nicht.

          Code:
          if (sh.Schalten.Strom.Kaffeemaschine() == 1):
              sh.Join(text='Kaffeemaschine läuft', title='Smarthome Join', icon='http://www.smartvisu.de/data/smartvisu_l.png', vibration='True',)
          Code:
          2017-07-11  19:03:03 ERROR    test         Logic: test, File: /usr/local/smarthome/logics/test.py, Line: 2, Method: <module>, Exception: 'Join' object is not callable
          Traceback (most recent call last):
            File "/usr/local/smarthome/lib/scheduler.py", line 378, in _task
              exec(obj.bytecode)
            File "/usr/local/smarthome/logics/test.py", line 2, in <module>
              sh.Join(text='Kaffeemaschine läuft', title='Smarthome Join', icon='http://www.smartvisu.de/data/smartvisu_l.png', vibration='True',)
          TypeError: 'Join' object is not callable

          Kommentar


            #6
            Was versuchst Du denn zu erreichen. Indem Du die Klasse aufrufst?

            von den Parametern her sieht das aus als wolltest Du die Methode send_notification aufrufen.
            Viele Grüße
            Martin

            There is no cloud. It's only someone else's computer.

            Kommentar


              #7
              Ja das hab ich erst mal als Test.
              Erst mal das eine um den Verstand zu bekommen, dann mache ich den Rest.

              Verstehe ich da was Falsch? Im sh wird doch immer die class angegeben welche ich ansprechen möchte und fülle dann die Variabelen oder??

              Kommentar


                #8
                Join ist bei Dir aber keine Variable sondern eine Klasse. Zuweisen kannst Du der Klasse aber nur Werte indem Du die definierten Methoden aufrufst.

                was willst Du denn generell erreichen. Bei mir entsteht im Moment der Verdacht, dass Du für das was Du tun willst mit der Implementierung als Plugin vieleicht auf dem Holzweg bist.
                Viele Grüße
                Martin

                There is no cloud. It's only someone else's computer.

                Kommentar


                  #9
                  Es dämmert du meinst sh.Join.send_notification....

                  Ich möchte es so machen wie in pushbullet oder nma. Einfach nur den http POST ausführen. Manuell funktioniert das.

                  Kommentar


                    #10
                    Gibt es hier schon was neues? Ich wäre auch an der Lösung interessiert.

                    Gruß

                    Sprocky

                    Kommentar


                      #11
                      Sprocky du meinst zum gesamtzusammenspiel? das join plugin ist mitlerweile Teil der Plugins: https://github.com/smarthomeNG/plugins/tree/master/join

                      Kommentar


                        #12
                        Das ganze ist ein zusammenspiel aus den oben genannten Apps. Ich habe es mit Alexa halbwegs am laufen da es wohl noch mit der Deutschen Sprache beim Google Home hängt.

                        Guggst du hier:

                        Natural Language:
                        https://www.youtube.com/watch?v=55lfdlVZHOc

                        Tasker Ifttt Join:
                        https://joaoapps.com/google-assistan...r-awesomeness/

                        Das Alexa Plugin brauchst du nicht, es ist alles mit dem Speech Parser Plugin machbar. Einzigster Nachteil der das ganze hat ist das man immer sagen muss "Alexa starte AutoVoice und dann erst den Command"

                        Kommentar


                          #13
                          Danke für die Rückmeldung. Muss ich dann auf meinem Smartphone "OK Google, Starte Alexa Auto Voice, Licht Wohnzimmer ein" sagen?

                          Kommentar


                            #14
                            In meiner Google App kann man ja heute schon jede Menge Plugins auswählen, wie z.B. Philips HUE, siehe Screenshots. Wäre so ein Plugin für Smartphone.py nicht was?
                            You do not have permission to view this gallery.
                            This gallery has 2 photos.

                            Kommentar


                              #15
                              Nein, entweder OK Google frage Autovoice oder Alexa..... Google Assistant bzw. Google Home hat derzeit noch keine Freigabe in Deutsch von Google. (Aussage des Entwicklers)

                              Für das bessere Verständnis wie ich es gerade am realisieren bin:

                              Alle Befehle werden in api.ai angelegt und mit AutoVoice verknüpft. Nun kommen alle Sprachbefehle mit Variablen im Handy an. Tasker verarbeitet die Variablen und macht ein HTTP Post auf das Speech Plugin. Das war es für die Spracheingabe!!
                              Wenn du einen Befehl direkt absetzen willst (nur für Google) kannst du entweder den Natural Language Button drücken oder OK Google deaktivieren und Autovoice aktivieren.

                              Möchtest du Sprachausgaben über einen Status automatisch gesagt bekommen wie z.B "Es regnet das Dachfenster ist offen" kommt das Plugin Join ins Spiel. Hier sendest du ebenfalls die Variablen an Tasker und dieser gibt die Sprachausgabe aus. Die Ausgabe erfolgt am Handy, da sich Alexa nicht von alleine aktivieren lässt.

                              Kommentar

                              Lädt...
                              X