I have never done HTTP before, but I have managed to create an html file that works fine from my browser. I would like to do this from OH3. I have installed the Binding and I think I configured the Thing, but I have not found any examples of how to do it. I have gone through the docs and a bunch of posts, but still have not found anything that really shows how to do it. It would be nice if someone has a doc that is HTTP for OpenHab a beginners tutorial. Once I see how to do it, I can comprehend pretty quickly.
My goal is to turn on my TV and get the status. Here are the 2 commands that work in the browser. I did it as a form so I could actually change the options before hitting submit.
I am trying to send commands to my IR controller that turns on my TV and then verify that it is on. I have to use http post to do this. Those commands work through the browser, but I would like to send them using OH3.
OH uses ‘0’ and ‘1’ as a switch status. So, when I query the device status (using a POST with idOperacion=1002), I have to convert its answer to a ‘0’ or a ‘1’. I use getEcoforestSwitch.js for that. It receives the device answer, parses it, and returns either a ‘0’ or a ‘1’. Therefore, even when I switch the device on/off using another method, OH is able to collect the actual status
When I want OH to switch the device on or off, I use cmdEcoforestSwitch.js for that. It receives either ‘0’ or ‘1’ as input and converts it to the string that the device expects to switch on or off. The binding sends this output to the device with a POST
This requires an HTTP binding version that, at the time of writing, is only available in snapshots. Probably it will be included in OH3.1.0.M2 by month end. My device accepts text/plain for the commands, in your case you should probably use text/xml or text/html.
My actual configuration has more channels. It’s a pellet stove and I use these other channels to control temperature and alarms. The concept is the similar to the switch shown above (the main difference is that you are not obliged to have ‘0’ and ‘1’ states).
Thank you for the help. This really got me started. I was actually able to send a command and turn on my TV using the following thing. When I turned on the switch, it sent the command and turned on the TV. Could you possibly give me some example of your scripts for idOperacion.
Good. But it seems that you are using the 3.0 http binding and not the snapshot one. With the 3.0 binding you will be able to send commands using POST but will not be able to read the TV status using POST (it only supports GET for state).
But one thing at the time. In my case I have onValue as “1” (and offValue as “0”) and use a js transformation to convert from 0 or 1 to the command that the device expects. Here is the code for cmdEcoforestSwitch.js (that I’ve created in conf/transform)
You can achieve something similar with onValue as “1” and offValue as “0” (this is just a guess)
(function(i) {
var resultado = "Method=IR_SendCommand&Param1=" + i + "&Param2=PhilipsTV&Param3=power";
return resultado.trim();
})(input)
If/when you use the enhanced http binding you will be able to query the state using POST. For now you can only use GET. The main difference is that you can use a body for POST but not for GET. In my example, to get the device status I send a POST with idOperacion=1002. The device returns something like