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
Look at the HTTP Binding
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?