- Platform information:
- Hardware: Synology DS920+
- OS: Docker on Synology DSM (BusyBox)
- openHAB version: Docker stable 3.3
- Issue of the topic: Scripting API calls for instances !=0
Since the official hyperion ng binding does’nt support LED hardware instances other then 0 i have to call the web rtc API. My setup is 5x WLED Quinled Dig Uno with SK6812 strips. One around the TV, the other behind every 5.1 speaker for a nice indirect light.
My problem is when starting or stopping hyperion ambilight only instance 0 (behind my TV) gets off. The other “sattelites” show the edged of the TV since hyperion is structured in a way that every instance has its own feature set.
The binding for hyperion ng is quite nice but is only able to talk to instance 0.
It cost me already hours scripting javascript or DSL so help would be much appreciated.
In general i “simply” would like to call the API twice:
- Switch to the device
{"command":"instance","subcommand":"switchTo","instance":1}
- Turn off LED device
{"command":"componentstate","componentstate":"component":"LEDDEVICE","state":false}
- Optional: Set up API key for security purposes
Here are a few failures i alredy made trying to simply calling the API and getting a serverinfo:
- with XMLHttpRequest
not possible because any require() throws an error
var XMLHttpRequest = require('xhr2');
var xhr = new XMLHttpRequest();
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
}
};
xhttp.open("POST", "http://192.168.0.5:8090/json-rpc", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send("{command:serverinfo,tan:1}");
- fetch
same problem, fetch seems to be not supported
const userAction = async () => {
const response = await fetch('http://192.168.0.5:8090/json-rpc', {
method: 'POST',
body: {"command":"serverinfo","tan":1}
headers: {'Content-Type': 'application/json'}
});
const myJson = await response.json();
logger.info(myJson);
}
- The official way from Actions | openHAB
also not working
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var url = "http://192.168.0.5:8090/json-rpc"
var content = "{command:serverinfo,tan:1}"
contentType = "Content-type = application/json"
var output = sendHttpPostRequest(url, contentType, content, 1000)
logger.info("output = "+output);
Could somone PLEASE provide me a working snippet i can work with?