Seite 2 von 2
Re: Rule für Item zu aktualisieren
Verfasst: 4. Mai 2020 19:52
von stargazer
Ja, VuPower schaltet mit dem Identischen Befehl jeweils Ein und Aus. Es wird eine Fernbedienung emuliert.
Als komplette Antwort kommt false bzw. true zurück.
Code: Alles auswählen
<e2powerstate>
<e2instandby> false </e2instandby>
</e2powerstate>
Siehe auch Enigma2 WebInterface API Documentation
https://dream.reichholf.net/e2web/
Re: Rule für Item zu aktualisieren
Verfasst: 6. Mai 2020 14:39
von udo1toni
Ich hab es jetzt nicht selbst ausprobiert, aber:
Eine Datei boolonoff.js:
Code: Alles auswählen
(function(i) {
var status = ""
if(i.includes("true")) {
status = "OFF"
} else {
status = "ON"
}
return status;
})(input)
Und folgendes Item:
Code: Alles auswählen
Switch VuPower "Power [%s]" <switch> (gVu) {http="<[http://root:Passwort@10.10.10.10:80/web/powerstate:3000:JS(boolonoff.js)] >[*:GET:http://root:Passwort@10.10.10.10:80/web/remotecontrol?command=116]"}
Sollte eigentlich ohne weitere Rules ausreichen.
Die JS Transformation gibt entweder ON oder OFF aus, je nachdem, ob der zurückgelieferte String den Teilstring "true" enthält oder nicht.
Eventuell könnte die js-Datei sogar so aussehen:
Code: Alles auswählen
(function(i) {
return if(i.includes("true")) {"OFF"} else {"ON"};
})(input)
Das müsste man halt ausprobieren.
Falls im Ergebnis der Abfrage auch noch andere Werte vorkommen, kann man in js natürlich auch noch per RegEx oder anderen Verfahren den String entsprechend einkürzen.
Re: Rule für Item zu aktualisieren
Verfasst: 6. Mai 2020 18:40
von stargazer
Erstmal vielen Dank für deine Mühe.
Nachdem ich das Javascript Transformation installiert hab erhalte ich bei ersten Script
Code: Alles auswählen
org.openhab.core.transform.TransformationException: An error occurred while executing script. TypeError: i.includes is not a function in <eval> at line number 3
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:218) [bundleFile:?]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) [bundleFile:?]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-06 18:27:37.223 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JS(boolonoff.js)' threw an exception. [response=
<html>
<head><title>401 - Unauthorized</title></head>
<body>
<h1>Unauthorized</h1>
<p>401 Authentication required</p>
</body>
</html>
und beim zweiten
Code: Alles auswählen
org.openhab.core.transform.TransformationException: An error occurred while loading JavaScript. <eval>:2:11 Expected an operand but found if
return if(i.includes("true")) {"OFF"} else {"ON"};
^ in <eval> at line number 2 at column number 11
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:71) ~[bundleFile:?]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:218) [bundleFile:?]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) [bundleFile:?]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-06 18:31:14.087 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JS(boolonoff.js)' threw an exception. [response=
<html>
<head><title>401 - Unauthorized</title></head>
<body>
<h1>Unauthorized</h1>
<p>401 Authentication required</p>
</body>
</html>
Re: Rule für Item zu aktualisieren
Verfasst: 8. Mai 2020 16:57
von udo1toni
Hmm... Ich hätte eigentlich erwartet, dass includes funktioniert (das ist der erste Teil der Fehlermeldung: ... not a function in <eval>...)
Allerdings wird schon der Seiteninhalt nicht korrekt geladen. (Der Teil mit Unauthorized) Da sind also die Zugangsdaten nicht korrekt.
Wegen fehlendem includes muss ich erst mal nachschauen...