Is anyone sending commands to the REST API from a sitemap? I’m trying to determine if I can send user code configuration to a smart lock from a sitemap or habpanel widget.
Or, rather build a text box that allows me to send 4 to 8 digit codes to the smart lock for lock access rather than using the binding. A easy to use interface to allow code creation/deletion.
What you are really asking is whether you can create a web page that is included on your sitemap that has a form and when clicking on “send” it posts the contents of the form to an Item, right?
I can’t help with the form part but I can say that it’s possible. If you look at OAuth2 using just OH Rules and myopenhab.org, you will see that I have a call to set an OH Item when a web page get’s loaded. In this case the page get’s loaded through myopenhab.org with an argument, but you should be able to use it as an example to build up something that might work for you.
Apart from the suggestions made by Rich, to answer your initial question:
Yes that can be done. Using the http binding and the REST API you can make an item that sends a command to an item.
If you want to send a state to a certain item, you can POST that state (for example ON or OFF for a switch) to http://yourIP:port/rest/items/yourItem.
The documentation of the http binding shows examples of that.
Thanks Rolf, im quite OK sending HTTP commands to items, that’s fairly straight forward. Its the REST component and storing values from a form that is a little trickier in a site map.
In any case I think Rich’s solution will work just fine and is not too dissimilar to that with patrick uses in the spotify API web player. between the two i think I can make a workable solution
I know, in general setting up an item to send a command to an item doesn’t make sense, but what I imagined would for example be that you make an item that sends a 1 to the “overall” number code item, make a button that sends a 2, and so on.
Those items can then be put in a sitemap, and you can use the overall number code item to handle the input and so on.
I’ve managed to create already a simple angular widget which is populating the string items for user_code and user_code_label. As the Door lock has many slots available for codes, I need to either settle on a fixed position for the code, say 10. Or create a few different fields to insert up to 5 codes. Tricky.
So I can populate the string items from the widget. This works fine.
Using a sample rule I found for Kodi, I’ve modified it but am confused as to how I can populate the
var String jsondata
variable, with the content of my string item? Does this rule look correct?
e.g
ITEM:
/* Data for Slot 5*/
String user_code_label_5
String user_code_5
RULE
// Use the Names and Codes to Program the Lock
rule "Received Guest Name & Code"
when
Item guest_5 received command ON
then
val String URL = "http://192.168.0.3:8080/rest/things/zwave%3Adevice%3Aa1562d1c%3Anode28/config"
var String guestcode = user_code_5.state.toString
var String contenttype = "application/json"
var String jsondata = '{"usercode_code_5": '+guestcode+'}'
logInfo("Door Guest Name", "Programming new Guest " + user_code_label_5.state+ " with Code " + user_code_5.state + " to Front Door Lock.")
sendHttpPostRequest(URL, contenttype, jsondata)
end
Any suggestions as it runs just fine but does not populate the API with the details. The logging indicates no errors. Ive tried a thousand combinations haha!
When I used the rest API to configure the THING, it was done successfully using this command: