XBMC -> FHEM

Begonnen von Zwiebel, 23 August 2013, 18:55:42

Vorheriges Thema - Nächstes Thema

Zwiebel

Hallo,

ich hab ein XBMC Modul geschrieben mit dem man FHEM steuern kann. (ein modul für XBMC nicht für FHEM)

Hintergrund ist der: Mein NAS läuft nicht dauernt. Kann aber und via FHEM angeschaltet werden. Relais board an der Fritzbox(FHEM).
Jetzt war es immer notwendig per Smartphone oder PC das NAS auf "on" zu schalten.

Das geht jetzt gleich aus dem XBMC raus.

Mal schauen wie das mit dem add-on funktioniert. Vielleicht bekomm ich noch mehr implementiert..

gruß
Zwiebel

Puschel74

Hallo,

cool.
Ab ins Wiki damit bitte.

Grüße
Zotac BI323 als Server mit DBLog
CUNO für FHT80B, 3 HM-Lan per vCCU, RasPi mit CUL433 für Somfy-Rollo (F2F), RasPi mit I2C(LM75) (F2F), RasPi für Panstamp+Vegetronix +SONOS(F2F)
Ich beantworte keine Supportanfragen per PM! Bitte im Forum suchen oder einen Beitrag erstellen.

reacend

#2
Coole Sache,
wollte gestern auch was dazuprogrammieren, aber naja meine kentnisse in Python sind doch recht begrenzt.
genial wäre eine Steuerung der lichter, wenn z.b. Der Film anfängt usw.

Und eventuell mehrere geräte die man einschalten bzw. ausschalten kann, die man hinzufügt...

Geht das?

BG,
Mark

Hans Franz

#3
Zitat von: reacend am 18 Oktober 2013, 21:20:02
genial wäre eine Steuerung der lichter, wenn z.b. Der Film anfängt usw.

Yep,
Ich hoffe Zwiebel macht noch weiter.
Aber Dank copy and paste bin ich auf das hier gekommen:
http://www.jordanhackworth.com/home-automation-with-xbmc/

In ~/.xbmc/scripts/ folgenden Code als playeraction.py speichern

import xbmc,xbmcgui
import subprocess,os

class MyPlayer(xbmc.Player) :
 
  def __init__ (self):
      xbmc.Player.__init__(self)
   
  def onPlayBackStarted(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A on"')
     
  def onPlayBackEnded(self):
    if (VIDEO == 1):
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackStopped(self):
    if (VIDEO == 1):
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackPaused(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackResumed(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A on"')
     
player=MyPlayer()

VIDEO = 0

while not xbmc.abortRequested:
  if xbmc.Player().isPlaying():
    if xbmc.Player().isPlayingVideo():
      VIDEO = 1
    else:
      VIDEO = 0
  xbmc.sleep(1000)


Den wget-String natürlich anpassen.

In ~/.xbmc/userdata/ noch folgendes als autoexec.py
import os
import xbmc
xbmc.executescript('special://home/scripts/playeraction.py')


Funktioniert bei mir ausgezeichnet.

Gruss
Hans
Raspi
CUL, Nano-CUL
FHT8V, FHT80B, S300TH
WM1000WZ, ELRO
LW12, LD382,DS18B20

Makkoo

Cool das gefällt mir :)
So kann ich theater Light simulieren :)

dennisb

Hi,

mit dem XBMC Modul (ab sofort im SVN, sollte ab morgen übers update ausgeliefert werden) kann man auch auf play, pause, etc. reagieren. Hier ein Beispiel:
define xbmc_lighton notify xbmcDeviceName.playStatus:.playing set Lampenname on
define xbmc_lightoff notify xbmcDeviceName.playStatus:.playing set Lampenname off

Das ist eventuell auch interessant für euch.

Gruß
Dennis

strauch

Cool wäre so ein Dashboard für Xbmc, wo man sich die Infos die man gerne hätte am XBMC anschauen kann. Temperaturen, sind die Fenster offen oder zu o.ä.
FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.

d0np3p3

Ja und auch steuern kann, das wäre nice.
Da fällt mir ein ich werde gleich mal ein notify schreiben das die Heizung nicht auf 17°C runterregelt, solange der XBMC spielt...
FHEM: Raspberry Pi (COC) & Fritz 7270 (freetz FHEM2FHEM)
IT (Elro AB440 AB600D) - Max! (6*regler 1*Thermostat 5*Fenster) Hue Bridge mit Bulbs - 2*Living-white Adapter - Iris
XBMC (Zbox) 4*SqueezeRadios 3*squeezelite dbox
AndFhem (Nexus4)

strauch

Gute Idee :-)

Gesendet von meinem Nexus 4 mit Tapatalk

FHEM 5.6 VMware mit Debian. 1 CUL für FS20 und HMLAN für Homematic, HM-CC-RT-DN, HM-LC_Sw1PBU-FM, HM-LC-Bl1PBU-FM,  HM-SEC-SC, HM-SEC-SC-2, HM-LC-Sw1-Pl2, HM-Sec-RHS, ASH2200, FHT80B, S20KSE, Sonos, XBMC, FB_Callmonitor, SMLUSB, Arduino Firmata, uvm.

Hans Franz

Zitat von: strauch am 09 Januar 2014, 11:17:49
Cool wäre so ein Dashboard für Xbmc, wo man sich die Infos die man gerne hätte am XBMC anschauen kann. Temperaturen, sind die Fenster offen oder zu o.ä.
Gibt es, allerdings nur rudimentär. Ist auch schon 2 Jahre alt und bedingt ein Erweitern/Ändern des Quellcodes sowie ein sehr mühsames Gefummel im Code (xml) des Skins.
https://github.com/Memphiz/script.xbmc.fhem/tree/master/script.xbmc.fhem

Gruß
Hans

Raspi
CUL, Nano-CUL
FHT8V, FHT80B, S300TH
WM1000WZ, ELRO
LW12, LD382,DS18B20

SirMarco

Zitat von: Hans Franz am 21 Oktober 2013, 02:35:55
Yep,
Ich hoffe Zwiebel macht noch weiter.
Aber Dank copy and paste bin ich auf das hier gekommen:
http://www.jordanhackworth.com/home-automation-with-xbmc/

In ~/.xbmc/scripts/ folgenden Code als playeraction.py speichern

import xbmc,xbmcgui
import subprocess,os

class MyPlayer(xbmc.Player) :
 
  def __init__ (self):
      xbmc.Player.__init__(self)
   
  def onPlayBackStarted(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A on"')
     
  def onPlayBackEnded(self):
    if (VIDEO == 1):
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackStopped(self):
    if (VIDEO == 1):
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackPaused(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A off"')
     
  def onPlayBackResumed(self):
    if xbmc.Player().isPlayingVideo():
      os.system('wget "http://raspberrypi:8083/fhem?cmd=set ELRO_F0000_A on"')
     
player=MyPlayer()

VIDEO = 0

while not xbmc.abortRequested:
  if xbmc.Player().isPlaying():
    if xbmc.Player().isPlayingVideo():
      VIDEO = 1
    else:
      VIDEO = 0
  xbmc.sleep(1000)


Den wget-String natürlich anpassen.

In ~/.xbmc/userdata/ noch folgendes als autoexec.py
import os
import xbmc
xbmc.executescript('special://home/scripts/playeraction.py')


Funktioniert bei mir ausgezeichnet.

Gruss
Hans

Echt Klasse :-) Es läuft bei mir....

Noch eine Idee wie man das ganze ich Cinema Experience einbauen kann?

Hans Franz

Zitat von: SirMarco am 26 Januar 2014, 13:22:07
Noch eine Idee wie man das ganze ich Cinema Experience einbauen kann?

Cinema Experience habe ich noch nicht benutzt, aber mir gerade 'mal angeschaut(OK, nur quergelesen):Die Datei home_automation.py sieht vielversprechend aus und scheint genau dafür  gedacht zu sein:.# place code below this line

Gruß
Hans
Raspi
CUL, Nano-CUL
FHT8V, FHT80B, S300TH
WM1000WZ, ELRO
LW12, LD382,DS18B20

Hans Franz

#12
Hallo,

Ich hab' da 'mal 'was gebastelt..
Um nicht mühsam für jeden Skin in XBMC den XML-Code zu bearbeiten, wie es für das Script von Memphiz erforderlich ist, habe ich es etwas umgeschrieben.
Es ist jetzt ein Programm in XBMC und zieht sich seine Informationen aus einem Dummy mit einem userattr namens xbmcInfo.

Das globale Attribut userattr muss mit "xbmcInfo" erweitert werden.
Entweder händisch oder so:
{fhem ("attr global userattr $attr{global}{userattr}"." xbmcInfo")}

Dann einen Dummy definieren und ihm das Attribut xbmcInfo verpassen.

Schema:
attr <dummy-name> xbmcInfo <TYPE> <Reading[|Alias]> <[Reading[|Alias]]>...


Beispiele:
define xbmc_dummy dummy
attr xbmc_dummy xbmcInfo CUL_WS temperature|Temperatur humidity|Luftfeuchte

define xbmc_dummy2 dummy
attr xbmc_dummy2 xbmcInfo PID20 actuation|Ventil desired|Soll measured|Ist delta p_p|P-Anteil p_i|I-Anteil

       
Gruß
Hans

Edith:
Version mit jsonlist2 statt xmllist
Sollte jetzt auch in Gotham installierbar sein.
Raspi
CUL, Nano-CUL
FHT8V, FHT80B, S300TH
WM1000WZ, ELRO
LW12, LD382,DS18B20

P.A.Trick

Cool erst einmal Danke für das Skript. Allerdings bekomme ich beim Empfangen der XML Liste einen Fehler angezeigt. Any hints?

14:50:57 T:2706373440   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <class 'xml.parsers.expat.ExpatError'>
                                            Error Contents: not well-formed (invalid token): line 1479, column 67
                                            Traceback (most recent call last):
                                              File "/home/murdoc/.xbmc/addons/script.xbmc.fheminfo/fhemmain.py", line 48, in <module>
                                                fetchFhem()
                                              File "/home/murdoc/.xbmc/addons/script.xbmc.fheminfo/fhemmain.py", line 41, in fetchFhem
                                                ret = fhem_fetch(hostip, hostport, telnetpasswd)
                                              File "/home/murdoc/.xbmc/addons/script.xbmc.fheminfo/resources/lib/fhem.py", line 65, in fhem_fetch
                                                ret = fhem_parseXML(xmlstr)
                                              File "/home/murdoc/.xbmc/addons/script.xbmc.fheminfo/resources/lib/fhem.py", line 90, in fhem_parseXML
                                                fhemcontents = xmltree.fromstring(xmlstr)
                                              File "/home/murdoc/.xbmc/addons/script.module.elementtree/lib/elementtree/ElementTree.py", line 1012, in XML
                                                return api.fromstring(text)
                                              File "/home/murdoc/.xbmc/addons/script.module.elementtree/lib/elementtree/ElementTree.py", line 182, in fromstring
                                                parser.feed(text)
                                              File "/home/murdoc/.xbmc/addons/script.module.elementtree/lib/elementtree/ElementTree.py", line 1292, in feed
                                                self._parser.Parse(data, 0)
                                            ExpatError: not well-formed (invalid token): line 1479, column 67
                                            -->End of Python script error report<--
Cubietruck,RPI,QNAP Ts-419p+, FS20, FRITZ!DECT200, 7 MAX! Thermostate, 3 MAX! Fensterkontakte, Kodi, CUL V3.3, EM1000S, LW12, LD382, HUE, HM-CFG-USB-2, 1x HM-LC-SW1-FM, 2x HM-LC-SW2-FM, 2x HM-LC-Sw1PBU-FM, 3xHM-LC-Bl1PBU-FM,HM-SEC-RHS, 2xHM-SEC-SD,HM-WDS30-T-O, 3x HM-LC-Dim1TPBU-FM, RPI+AddOn

Hans Franz

Hallo,

Sorry, aber ich befürchte, deine XML-Liste ist nicht ganz korrekt. Hatte ich vor Monaten auch einmal, weiß aber die genauen Umstände nicht mehr. Ist oft schwer zu finden :'(

Gruß
Hans
Raspi
CUL, Nano-CUL
FHT8V, FHT80B, S300TH
WM1000WZ, ELRO
LW12, LD382,DS18B20