Hallo zusammen,
meine Funktion bekommt aus dem notify eines dummys werte (on, off, rgb ffffff) übergeben. Nun möchte ich ein Skript nutzen, um den dummy (hier milight) zu steuern.
Hier die Funktion:
sub set_milight($) {
my ($command) = @_;
my $string = "";
if (lc($command) eq "on") {
system("/opt/fhem/FhemUtils/milight-home_2.py 8 3 ON");
}
elsif (lc($command) eq "off") {
system("/opt/fhem/FhemUtils/milight-home_2.py 8 3 OFF");
}
# python milight-home_2.py 8 3 COLOR "#ff0000"
#system("/opt/fhem/FhemUtils/python milight-home_2.py 8 3 COLOR "#ff0000"")
else { # respone is "rgb "
$command =~ tr/rgb /#/d;
$string = '"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "' . $command . '"&"' ;
system($string);
}
return $string;
}
Als Ausgabe bekomme ich: "/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "#ffffff"&" (Aufruf mit rgb ffffff) Allerdings wird der Befehl system($string) nicht (korrekt) ausgeführt. Evtl. verhaue ich mich auch mit den " und den '?
On & Off funktionieren
Für Hilfe bin ich wieder einmal dankbar. :-)
Grüße
Thomas
Probiere mal bitte
#$string = '"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "' . $command . '"&"' ;
#system($string);
fhem("/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR $command");
dann bekomme ich das:
2019.03.06 14:32:57 3 : /opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR #ff0000 : Unknown command /opt/fhem/FhemUtils/milight-home_2.py, try help.
würde da so nicht auch die " bei dem "#ffffff" fehlen?
Abgesehen davon, dass ich es auch so machen würde wie Cooltux (ich glaube aber da muss noch einmal "" rein) , nimm doch FHEM zum debuggen.
Die entscheidenden zwei Zeilen etwas modifiziert in die FHEM Kommandozeile geworfen:
{my $command =~ tr/rgb /#/d;; my $string = '"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "' . $command . '"&"' }
ergeben
Zitat"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR ""&"
.
Das willst Du doch nicht? Also 2. Versuch, die unnötigen " weg:
{my $command =~ tr/rgb /#/d;; my $string = '/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR ' . $command . '&' }
Zitat/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR &
Sieht gut aus.
Noch einfacher:
{my $command =~ tr/rgb /#/d;; my $string = "/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR $command &" }
liefert das gleiche Ergebnis.
Ok $command ist in meinem Test leer, könnte man jetzt noch mit etwas ersetzen.
Gruß Otto
Ich merke gerade: in Cooltux seiner Variante müsste man fhem('" Befehl"') machen. dann wird aber die Variable $command nicht aufgelöst.
Ich hatte das hier (https://heinz-otto.blogspot.com/2018/02/in-fhem-externe-programme-aufrufen.html)mal etwas durchgearbeitet.
Gruß Otto
Zitat von: CoolTux am 06 März 2019, 14:25:00
Probiere mal bitte
#$string = '"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "' . $command . '"&"' ;
#system($string);
fhem("/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR $command");
Mist, Otto hat Recht. Ganz vergessen.
#$string = '"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR "' . $command . '"&"' ;
#system($string);
fhem("\"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR $command\"");
[/quote]
Hoffe so geht es besser
@CoolTux
mit Deiner Variante bekomme ich gar keine Ausgabe
EDIT: Vergiss es, hatte string noch al returnwert drin. Die Farbe ändert sich trotzdem nicht
@Otto123
Der eigentlich Aufruf sollte eigentlich so lauten:
#system("/opt/fhem/FhemUtils/python milight-home_2.py 8 3 COLOR "#ff0000" &")
warum soll das system jetzt mit fhem("") ersetzt werden? btw die "" bei dem hexwert brauche ich auch
Natürlich bekommst Du keine Ausgabe. Es gibt auch bei system() keine Ausgabe ausser eine nichts sagende -1.
system() kann aber FHEM blockieren wenn nicht mit & der aufrufende Befehl in den Hintergrund geschickt wird.
fhem("\"/opt/fhem/FhemUtils/python milight-home_2.py 8 3 COLOR \"#ff0000\"\"");
Und wenn Du es so machst. Ich merke ich schon ich werde wohl nachher mal selber testen müssen.
mit
$command =~ tr/rgb /"#/d;
$command = $command . '"';
fhem("\"/opt/fhem/FhemUtils/milight-home_2.py 8 3 COLOR $command\"");
klappt es jetzt bei mir.
ZitatNatürlich bekommst Du keine Ausgabe. Es gibt auch bei system()
Ich hatte am Ende noch ein return $string drin :-)