[SOLVED] Switching Sonoff 4CH Modul with HTTP-binding

Hello

I plan to switch a 4-Chanel WiFi-Switch with HTTP-Binding. I’ve defined this item:

Switch wiFiGarten1   "Lichtkette"   <light> (Garden)    {http=">[ON:POST:http://192.168.xxx.xxx/cm?cmnd=Power1%20ON]>[OFF:POST:http://192.168.xxx.xxx/cm?cmnd=Power1%20OFF]"}

When I post single command string (http=">[ON:POST:http://192.168.xxx.xxx/cm?cmnd=Power1%20ON]) in browser it works. But switching with habpanel-switch don’t leads to success.
In Log appears:

2019-05-01 14:48:12.688 [vent.ItemStateChangedEvent] - wiFiGarten1 changed from ON to OFF

any hints?

  • Platform information:
    • Hardware: VN
    • OS: SuSe Leap 15
    • Java Runtime Environment: IcedTea 3.11.0
    • openHAB version: 2.4 Stable

You were close, but…

Switch wiFiGarten1 "Lichtkette" <light> (Garden) {http=">[ON:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20On] >[OFF:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20Off]"}

Hi Jürgen,

I’ve tried this, but it doesn’t work also. When switching on in log appears:

java.util.UnknownFormatConversionException: Conversion = 'O'
    at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691) ~[?:?]
    at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720) ~[?:?]
    at java.util.Formatter.parse(Formatter.java:2560) ~[?:?]
    at java.util.Formatter.format(Formatter.java:2501) ~[?:?]
    at java.util.Formatter.format(Formatter.java:2455) ~[?:?]
    at java.lang.String.format(String.java:2940) ~[?:?]
    at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:267) ~[?:?]
    at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:130) ~[?:?]
    at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:94) ~[?:?]
    at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:45) ~[?:?]
    at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [3:org.apache.karaf.services.eventadmin:4.2.1]
    at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [3:org.apache.karaf.services.eventadmin:4.2.1]
    at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [3:org.apache.karaf.services.eventadmin:4.2.1]
    at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [3:org.apache.karaf.services.eventadmin:4.2.1]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]

I think there is a prameter missing:

Switch wiFiGarten1 "Lichtkette" <light> (Garden) {http="
>[ON:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20On:default]  >OFF:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20Off:default]
"}

Notice the :default at the end of each request.

@amsd
I received this error when trying it with a single “%”. Did you notice the “%%”?

@Confectrician
The posted code worked for me ( with my IP setting).

I have found examples in the docs which are leaving the transformation out,
so your example should work. :+1:

I would guess the double % could be the reason.

Unfortunately it also doesn’t work with double %. When I send the inital String directly in browser, it works. I think the fault is not in that part.

All I can say is: I tried your item definition getting your result. Posted directly in browser and it worked. Changing the item definition as posted above and it worked.

Could you post your actually used item?

Switch wiFiGarten1 “Leuchter” (Garden) {http=">[ON:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20ON]>[OFF:GET:http://192.168.xxx.xxx/cm?cmnd=Power1%%20OFF]"}

Try it “On” and “Off” as I posted.

no change

Is that a 100% copy of your item?

If yes, you should try to add a space between the ON and the OFF commands

Switch wiFiGarten1 “Leuchter” (Garden) {http=">[ON:GET:[http://192.168.xxx.xxx/cm?cmnd=Power1%%20ON] >[OFF:GET:[http://192.168.xxx.xxx/cm?cmnd=Power1%%20OFF]"}

Please also use code fences for such postings, since the forum software seems to make links from your item.

1 Like

That’s it! Thanks a lot for testing for me. Sometimes little things make the difference.

Just verified the same on my test installation.

1 Like