- Platform information:
- Hardware: Dell R710
- OS: Vmware->Ubuntu->Rancher->Docker
- openHAB version:OH3 M5
My old setup needed to be retired, so I thought I would give OH3 M5 a crack.
Its pretty awesome, alot of clicking and typing.
But on topic.
OH3 doesnt seem to have a Sony TV binding… I was using a OH1 binding in OH2. But this trick didn’t work on OH3.
So I built a TV API broker with python and flask that you can either getStatus or setStatus. I got getStatus returning json and used new ECMA scripting to make the request and parse json response and update relevant items.
But this where I got stuck with ECMA, I want one script to be called for all TV changes.
My API supports set (power, volume) and value (on/off, 0 - 100)
Ideally I want one script that will fire on any TV item change and build a restful request.
Can I do this with ECMA scripting? I presume so - but im new to this fancy pant javascripting thing.
I have currently linked this script to one rule linked to one item (ideally I dont want to have a script for each action for each tv
var client = java.net.http.HttpClient.newBuilder().build();
function httpGetStatus(uri, pTV, pPIN, pSet, pValue) {
try {
var request = java.net.http.HttpRequest.newBuilder()
.GET()
.uri(java.net.URI.create(uri))
.header(“TV”, pTV)
.header(“PIN”, pPIN)
.header(“SET”, pSet)
.header(“VALUE”, pValue)
.build();
var response = client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
// print(response.body());
return response;
} catch (e) {
print(e);
}
}var currentState = Bedroom5_TV_power.state
var result = JSON.parse(httpGetStatus( “http://192.168.1.21:7000/setStatus”
, ‘192.168.1.36’, ‘1234’, ‘power’, currentState.toString
).body());
Then of course I may have gone down the complete wrong path!
Another option is getting python to integrate with MQTT… but really thought it might be interesting to do it via rest api.