If I open page http://192.168.1.3:6001/do.nes?arguments=100, then my lamp is ON. http://192.168.1.3:6001/do.nes?arguments=0 - toggle to OFF.
How to set up OpenHAB for this?
Thank you in advance
I had the same problem when I started with openHAB, I ended up doing it like this.
Item
Switch networkLamp "Lamp"
Sitemap
Switch item=networkLamp
Rule
rule "Network Lamp ON"
when
Item networkLamp received update ON
then
sendHttpGetRequest("http://192.168.1.3:6001/do.nes?arguments=100")
end
rule "Network Lamp OFF"
when
Item networkLamp received update OFF
then
sendHttpGetRequest("http://192.168.1.3:6001/do.nes?arguments=0")
end
It is better to use the HTTP binding directly, e.g.
Switch networkLamp {http=">[ON:POST:http://192.168.1.3:6001/do.nes?arguments=0]" >[OFF:POST:http://192.168.1.3:6001/do.nes?arguments=100]"}
If you want to have it in the rules then this might make it tidier:
rule "Network Lamp"
when
Item networkLamp received command
then
switch(receivedCommand) {
case ON : sendHttpGetRequest("http://192.168.1.3:6001/do.nes?arguments=100")
case OFF : sendHttpGetRequest("http://192.168.1.3:6001/do.nes?arguments=0")
}
end
Do you have any example on how to do that, when there are mapping involved too? I got a switch to control the pan and tilt on a webcam, and skipping the rules could make that a lot simpler to look at.
My sitemap is defined like this
Switch item=GarageCamPosition label="Target" mappings=[0="Car", 1="Door"]
and the item like this
String GarageCamPosition "Camera position [%s]" <webcam> (all)
I do not see how this is related to the http binding.
I would stick with a rule in your case.
@martin_klimke, @rlkoshak, @Mikey Okay… At this point I think I’m just missing something blatantly obvious…
This is my items:
Switch Popcorn “Popcorn” { http=">[ON:POST:http://192.168.86.120:8083/JS/Run/zwave.devices[4].instances[0].commandClasses[0x20].Set(255)] >[OFF:POST:http://192.168.86.120:8083/JS/Run/zwave.devices[4].instances[0].commandClasses[0x20].Set(0)] }
My SiteMap:
sitemap home label=“The Smart Bachelor Pad”
{
Frame label=“Kitchen” {
Colorpicker item=TrackLights label="Kitchen Track Lights"
Colorpicker item=StripLights label="Kitchen Strip Lights"
Colorpicker item=lKitchen label="All Kitchen Lights"
Switch item=Popcorn label=“Popcorn Machine”
}
Frame label=“Living Room” {
Colorpicker item=Sconce label="Living Room Wall Lights"
Colorpicker item=lrLights label="All Living Room Lights"
Switch item=Fireplace label=“Fireplace” mappings=[PowerToggle=“On/Off”]
}
Frame label=“Main Controls” {
Switch item=BuildingDoors
Text item=DoorBell
Colorpicker item=gLights
Switch item=Sonos_Favorite mappings=[“Classic Rock’s Greatest Hits”=“Classic Rock”,“Wobblin’ Dubstep”=“Dubstep”,“Hazy Indie Summer”=“Indie”]
}
My log:
01:02:03.120 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'http.items’
01:02:03.153 [WARN ] [.internal.HttpGenericBindingProvider] - bindingConfig is NULL (item=Popcorn (Type=SwitchItem, State=Uninitialized)) -> process bindingConfig aborted!
What am I doing wrong!!??
You may have to escape or use URL encoding for the square brackets and parens that are part of the URL.
I’m still learning, but could you elaborate on how to escape them? Do I prefix it with “%” ?
So some quick google searching:
I made some adjustments to the items file:
[ = %5B
] = %5D
( = %28
) = %29
Switch Popcorn “Popcorn” { http=">[ON:POST:http://192.168.86.120:8083/JS/Run/zwave.devices[4].instances[0].commandClasses[0x20].Set(255)] >[OFF:POST:http://192.168.86.120:8083/JS/Run/zwave.devices[4].instances[0].commandClasses[0x20].Set(0)] }
I still get the same result tho
To escape them put a \ in front of them.
[
]
(
)
@rlkoshak
I’ve made the following adjustments by prefixing it with “”. No change
**Please note I have surrounded the \ with “” because when I originally posted it, the “” did not appear.
In my items file, I have prefixed every bracket and paran with \ no “” surrounding it.
Switch Popcorn “Popcorn Machine” { http=">[ON:POST:http://192.168.86.120:8083/JS/Run/zwave.devices""[4""].instances""[0""].commandClasses""[0x20""].Set""(255"")] >[OFF:POST:http://192.168.86.120:8083/JS/Run/zwave.devices""[4""].instances""[0""].commandClasses""[0x20""].Set""(0"")] }
Log:
17:49:55.597 [WARN ] [.internal.HttpGenericBindingProvider] - bindingConfig is NULL (item=Popcorn (Type=SwitchItem, State=Uninitialized)) -> process bindingConfig aborted!
17:50:33.816 [WARN ] [home.core.internal.items.ItemUpdater] - InstantiationException on org.eclipse.smarthome.core.library.types.StringType
That’s the point. By using the '' you are telling the openHAB software not to interpret those characters as special and pass them through unchanged. You should not see the ''.
Right, that makes sense. In that case I did edit the items fie accordingly, unfortunately, the result is the same .
Try to make it work with curl from the command line. There might be something wrong with the URL over all, a small typo or something.
It looks like the trailing quote mark is missing. Is that not needed?
{ http=">[ON:POST: URL] >[OFF:POST: URL ]"}
Good eye. Indeed the closing quote is required.
HA! Based on other things you’ve help me with my eye is only good when it’s not my config.
Okay So I’m getting closer. I got it to work using curl!
curl ‘http://192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(0)’ -u admin
Or
curl -g ’ curl ‘http://192.168.86.120:8083/ZWaveAPI/Run/devices[7].instances[0].commandClasses[0x20].Set(0)’ -u admin
Now… I face the next hurdle… Looks like I can only send this command if I include the -u parameter. Is there a way I can pass two additional parameters in OH in the items file in order to send the request?