Ankündigung

Einklappen
Keine Ankündigung bisher.

Chromecast Plugin

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

    #16
    Hallo,

    ich probiere das (delay) morgen mal aus. Jetzt schlafen die Kinder ;-)
    Bubbleupnp will ich nicht verwenden. Weitere Fehlerquelle.
    Ich habe stattdessen jetzt mal an einem Plugin geschrieben. Ich mache dazu gleich einen neuen Thread auf (hier)

    Gruß,
    Hendrik

    Kommentar


      #17
      Hallo,

      ich habe nur ca. vier Sekunden Verzögerung.

      Gruß,
      Hendrik

      Kommentar


        #18
        Ich werde das heute nachmittag auch mal testen, aber an 10 Sekunden nach Play drücken kann ich mich nicht erinnern (bin nicht der Hauptnutzer, sondern mein Sohn :-) ).
        Grüße
        Matze

        Kommentar


          #19
          OK Danke, werde dann mal auf Fehler suche gehen..

          Kommentar


            #20
            Moin,

            ich möchte hier meine "robuste" Audio-Lösung vorstellen.
            • Google Audio Chromecast
            • NodOn CRC-2-6-03 EnOcean Soft Remote Fernbedienung
            • Verstärker (AMPER502)
            • Lautsprecher (Outdoor)

            Bislang habe ich mit Euren Empfehlungen und Code-Schnipsel keine stabile Bedienung hinbekommen.
            Daher habe ich folgendes Framework hinzugezogen:
            https://home-assistant.io
            Home-Assistant biete eine Python-API die sehr einfach verwendet werden kann.
            Dies war ausreichend, um die Lautstärke zu regeln und Pause/Start auszuführen.
            Insbesondere bei Auswahl meiner Audio-Gruppe "Haus" oder "Bad" bin ich bislang an die Grenzen gestoßen...

            Der fürs Badezimmer geeignete Taster funkt über EnOcean.
            Mein EnOcean-KNX-Gateway übersetzt dies in eine KNX-Botschaft.
            Diese KNX-Botschaft löst folgende Logik aus ... und schon läuft alles wie gewünscht:
            Code:
            #!/usr/bin/env python3
            import homeassistant.remote as remote
            api = remote.API('127.0.0.1', 'mysmarthome')
            
            myhaus = remote.get_state(api, 'media_player.haus')
            mybad = remote.get_state(api, 'media_player.bad')
            md_status = False
            if (myhaus.state == 'playing') or (myhaus.state == 'paused'):
               my_md = 'media_player.haus'
               myvolume = myhaus.attributes['volume_level']
               md_status = True
            if (mybad.state == 'playing') or mybad.state == 'paused':
               my_md = 'media_player.bad'
               myvolume = mybad.attributes['volume_level']
               md_status = True
            
            source_item = sh.return_item(trigger['source'])
            nowstringsource_item = str(source_item)
            justroom = nowstringsource_item.split('.')
            
            if (len(justroom) > 2):
               logger.warning(justroom[2])
            if justroom[2] == 'plus' and md_status == True:
               myvolume = myvolume + 0.1
               if myvolume > 1:
                  myvolume = 1
                remote.call_service(api,'media_player','volume_set', {'entity_id': my_md, 'volume_level':myvolume})
            if justroom[2] == 'minus' and md_status == True:
               logger.warning(str(myvolume))
               myvolume = myvolume - 0.1
               if myvolume < 0.05:
                  myvolume = 0.05
                remote.call_service(api,'media_player','volume_set', {'entity_id': my_md, 'volume_level':myvolume})
            if justroom[2] == 'leererkreis' and md_status == True:
               remote.call_service(api,'media_player','media_play_pause', {'entity_id': my_md})
            Falls dies zukünftig mit einem "nativen" Smarthome.py Plug-In auch funktionieren sollte, würde ich mich freuen.

            Kommentar


              #21
              Nochmal hochgeschoben... hat jemand was in Richtung Chromecast gemacht?
              Derzeit zwischen Kistenauspacken und Garten anlegen.
              Baublog im Profil.

              Kommentar


                #22
                Ich meine, ich hätte ein Plugin fertig gemacht.
                muss ich bei geleGelegen Mal nachsehen.

                Kommentar


                  #23
                  Hallo,

                  so weit bin ich gekommen:
                  Code:
                  #!/usr/bin/env python3
                  # vim: set encoding=utf-8 tabstop=4 softtabstop=4 shiftwidth=4 expandtab
                  ################################################## #######################
                  # Copyright 2016- Hendrik Friedel
                  ################################################## #######################
                  # This file is part of SmartHomeNG
                  # https://github.com/smarthomeNG/smarthome
                  # http://knx-user-forum.de/
                  
                  # SmartHomeNG is free software: you can redistribute it and/or modify
                  # it under the terms of the GNU General Public License as published by
                  # the Free Software Foundation, either version 3 of the License, or
                  # (at your option) any later version.
                  #
                  # SmartHomeNG is distributed in the hope that it will be useful,
                  # but WITHOUT ANY WARRANTY; without even the implied warranty of
                  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
                  # GNU General Public License for more details.
                  #
                  # You should have received a copy of the GNU General Public License
                  # along with SmartHomeNG. If not, see <http://www.gnu.org/licenses/>.
                  ################################################## #######################
                  # with info from https://github.com/mknx/smarthome/wiki/Write-a-plugin-5-minutes
                  
                  from __future__ import print_function
                  import logging
                  from lib.model.smartplugin import SmartPlugin
                  import time
                  import pychromecast
                  
                  
                  class chromecast(SmartPlugin):
                  PLUGIN_VERSION = "1.1.2"
                  ALLOW_MULTIINSTANCE = True
                  
                  def find_cc(self, devicename):
                  chromecasts = pychromecast.get_chromecasts()
                  [cc.device.friendly_name for cc in chromecasts]
                  self.logger.info("[Chromecast] Searching for Devicename: {0}".format(self.devicename))
                  self.logger.info("[Chromecast] found: {0}".format(chromecasts))
                  cast = next(cc for cc in chromecasts if cc.device.friendly_name == self.devicename)
                  return cast
                  
                  def __init__(self, sh, cycle=30, devicename="Schlafzimmer"):
                  self._sh = sh
                  self._cycle = cycle
                  self.devicename = devicename
                  self.logger = logging.getLogger(__name__)
                  self.logger.info("[Chromecast] Starting Chromecast Instance for Devicename: {0}".format(self.devicename))
                  self.cast_status = False
                  self.media_status = False
                  print("###"+self.get_instance_name())
                  self.cast = self.find_cc(self.devicename)
                  self.cast.wait()
                  #sef.cast.device would now return DeviceStatus(friendly_name='Kinderbad', model_name='Chromecast Audio', manufacturer='Google Inc.', api_version=(1, 0), uuid=UUID('e9487631-2c48-cd63-5932-795bdb85f42a'), cast_type='audio')
                  #other parameters: cast.status, cast.media_controller
                  self.cast.socket_client.receiver_controller.regist er_status_listener(self)
                  self.cast.media_controller.register_status_listene r(self)
                  
                  def new_cast_status(self, status):
                  #self.cast_status = True
                  self.logger.info("[Chromecast] New. Cast status for {0}".format(self.devicename))
                  self._read_play_status()
                  
                  def new_media_status(self, status):
                  #self.media_status = True
                  self.logger.info("[Chromecast] New. Media status for {0}".format(self.devicename))
                  self._read_play_status()
                  
                  def run(self):
                  self.alive = True
                  #self._sh.scheduler.add(__name__, self._read_play_status, prio=5, cycle=self._cycle, offset=2) #actually we want to be notified. We need a callback or similar.
                  
                  def stop(self):
                  self.alive = False
                  #self._sh.scheduler.remove(__name__)
                  
                  def parse_item(self, item): #This is run once at start for each item. Here we could read in parameters
                  if 'cc_id' in item.conf:
                  if item.conf['cc_id']==self.devicename:
                  if 'cc_cmd' in item.conf:
                  value = item.conf['cc_cmd']
                  if value == 'player_state':
                  self.playerstate=item
                  return self.update_item
                  else:
                  return None
                  
                  def parse_logic(self, logic):
                  pass
                  
                  def update_item(self, item, caller=None, source=None, dest=None):
                  #called each time an item changes
                  self.logger.info('[Chromecast] Update Item triggered. Caller: {0} , Source: {1} , Dest: {2}'.format(caller,source,dest))
                  if not (caller == "Logic" and source== None) : # If triggered by logic, we caused this update ourselves (_read_play_status)
                  if self.has_iattr(item.conf, 'cc_cmd'): # does this check if the changed item has the parameter 'cc_player_state'?
                  if self.get_iattr_value(item.conf, 'cc_cmd')=='player_state':
                  mc=self.cast.media_controller
                  if item():
                  mc.play()
                  self.logger.info('[Chromecast] Setze Play status auf Play')
                  else:
                  mc.pause()
                  self.logger.info('[Chromecast] Setze Play status auf Pause')
                  if self.has_iattr(item.conf, 'cc_play_url'):
                  val = self.get_iattr(item.conf, 'cc_play_url')
                  url = val.split()[0]
                  type = val.split()[1]
                  mc=self.cast.media_controller
                  mc.play_media(url, type)
                  
                  
                  
                  def _read_play_status(self):
                  mc=self.cast.media_controller
                  res= (mc.status.player_state=="PLAYING")
                  self.logger.info('[Chromecast] Lese Play Status für Device {0} Ergebnis: {1}'.format(self.devicename,str(res)))
                  self.playerstate(res)
                  
                  
                  
                  
                  if __name__ == '__main__':
                  myplugin = chromecast('smarthome-dummy')
                  logging.basicConfig(level=logging.DEBUG, format='%(relativeCreated)6d %(threadName)s %(message)s')
                  #myplugin.dothis
                  Ich weiß darüber aber echt nix mehr. Probier's mal aus.

                  Gruß,
                  Hendrik

                  Kommentar

                  Lädt...
                  X