URL Request works in Browser but not as Item (Samsung_Multiroom_Speaker)

  • Platform information:
    • Hardware: ThinkPad SL500 Intel®Core™2 Due CPU T58707 4GB
    • OS: Ubuntu 18.04.4.LTS
    • openHAB version: openHAB 2.5.5

Hello everybody

For some time now I have been trying to address the API from my Samsung Speakers (https://www.samsung.com/ch/support/model/WAM350/EN/).
found the following information: (https://github.com/bacl/WAM_API_DOC).

The calls via the browser work as expected.
Now I’m trying to create a switch item with the http binding and e.g. to issue the mute command.
Unfortunately it does not work.
Maybe someone of you sees what is wrong with my item.
Switch WAM350_1_Mute "Mute ist [%s]" {http=">[ON:GET:http://192.168.1.60:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E] >[OFF:GET:http://192.168.1.60:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22off%22/%3E] <[http://192.168.1.60:55001/UIC?cmd=%3Cname%3EGetMute%3C/namePreformatted%3E:30000:XPATH(/UIC/response/mute)]"}

The Xpath transformation is also installed.
Here is the log file.

Somthing is wrong with java? java.util.IllegalFormatConversionException: c != java.util.Date???

2020-05-29 07:40:39.101 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'samsung-wam.items'
2020-05-29 07:45:00.750 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'samsung-wam.items'
2020-05-29 07:45:01.542 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-29 07:45:02.546 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-29 07:45:03.550 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-29 07:45:04.554 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-29 07:45:05.557 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]
2020-05-29 07:45:06.561 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.IllegalFormatConversionException: c != java.util.Date
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252]
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]       `84 - SetMute
Description: Mute ON

Example:

curl 'http://ip_speaker:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E' 
Xml string decoded:

<pwron>on</pwron><name>SetMute</name><p type="str" name="mute" val="on"/>`

Maybe someone can help me, would like to integrate the speakers into Openhab.
It must be a small but stupid mistake …

    `84 - SetMute
Description: Mute ON

Example:

curl 'http://ip_speaker:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E' 
Xml string decoded:

<pwron>on</pwron><name>SetMute</name><p type="str" name="mute" val="on"/>`

`<?xml version="1.0" encoding="UTF-8"?>
<UIC>
<method>MuteStatus</method>
<version>1.0</version>
<speakerip>192.168.1.60</speakerip>
<user_identifier></user_identifier>
<response result="ok">
    <mute>off</mute>
</response>
</UIC>`

I hope someone can figure this out…

First simplify. Just include one of the http endpoints on the Item. The most likely cause of the problem is the < config so let’s leave that one for last. First just include the >[ON config. Does that one alone work? If so add the >[OFF config. If not post the error. Don’t forget to sendCommand(ON) to the Item to test whether it works or not.

I’ve never seen this error before and it frankly doesn’t make much sense in context.

Hello Rich

Viele dank für deine Antwort.
Habe folgendes Item definiert und im HabPanel mit einem Switch-Widget verbunden.
Beim schalten pasiert nichts…
Das selbe Verhalten habe ich für das OFF.

image

The Item right now.
Switch WAM350_1_Mute "Mute" {http=">[ON:GET:http://192.168.1.60:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E]"}
the log-file
2020-05-29 19:18:55.938 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service java.util.IllegalFormatConversionException: c != java.util.Date at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) ~[?:1.8.0_252] at java.util.Formatter$FormatSpecifier.printCharacter(Formatter.java:2869) ~[?:1.8.0_252] at java.util.Formatter$FormatSpecifier.print(Formatter.java:2757) ~[?:1.8.0_252] at java.util.Formatter.format(Formatter.java:2520) ~[?:1.8.0_252] at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252] at java.lang.String.format(String.java:2940) ~[?:1.8.0_252] at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:168) ~[?:?] at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?] at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]

I also created a string item to possibly see the change via the interface.
Unfortunately, this never changes the value.
However, this call works without any problems in the browser
String WAM350_2_Mute "Mute [%s]" {http="<[http://192.168.1.60:55001/UIC?cmd=%3Cname%3EGetMute%3C/name%3E:30000:REGEX((.*))]"}

Unfortunately I have no idea what else I could try.

Does that error occur periodically or just when you send command ON to the Switch? Do you have any other HTTP binding Items or anything in http.cfg?

Now that I look at the error more closely, it looks like it’s complaining about a String formatter. Do you have any Item labels or Rules that use String::Formatter on a DateTime Item?

I included the Open-weather widget. a lot of items have been generated. otherwise I have no other items with a date.
I don’t have any rules running.
The Error occur just when i send the cmd

May i delete the Weather Items…
I’ll try that

Now there are no Items left, just the Item to sende the Mute Command.
This are the Logs

`2020-05-30 07:51:01.755 [ome.event.ItemCommandEvent] - Item ‘WAM350_1_Mute’ received command ON

==> /var/log/openhab2/openhab.log <==
2020-05-30 07:51:01.755 [WARN ] [org.apache.karaf.services.eventadmin] - EventAdmin: Exception during event dispatch [org.osgi.service.event.Event [topic=openhab/command/WAM350_1_Mute] {item=WAM350_1_Mute, bridgemarker=true, command=ON, timestamp=1590817861755} | {org.osgi.service.cm.ManagedService, org.osgi.service.event.EventHandler}={service.id=349, service.bundleid=249, service.scope=bundle, event.topics=openhab/*, service.pid=org.openhab.http, component.name=org.openhab.binding.http, component.id=13} | Bundle(org.openhab.binding.http_1.14.0 [249])]
java.util.UnknownFormatConversionException: Conversion = ‘m’
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691) ~[?:1.8.0_252]
at java.util.Formatter$FormatSpecifier.(Formatter.java:2720) ~[?:1.8.0_252]
at java.util.Formatter.parse(Formatter.java:2560) ~[?:1.8.0_252]
at java.util.Formatter.format(Formatter.java:2501) ~[?:1.8.0_252]
at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_252]
at java.lang.String.format(String.java:2940) ~[?:1.8.0_252]
at org.openhab.binding.http.internal.HttpBinding.formatAndExecute(HttpBinding.java:294) ~[?:?]
at org.openhab.binding.http.internal.HttpBinding.internalReceiveCommand(HttpBinding.java:147) ~[?:?]
at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:97) ~[?:?]
at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:49) ~[?:?]
at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:415) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:82) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104) [bundleFile:?]
at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:166) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_252]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_252]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_252]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_252]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_252]`

What is wrong with this request?

EDIT:
New Install Http-Binding didn’t help as well.
Is there a other way, that alows me to send this cmd?

Try getting rid of the URL encoding in the address. They really are not needed as the HTTP binding will URL encode those characters that need it for you anyway. It’s probably seeing the % characters and thinking they are String Formatter commands instead of URL encoding.

You can use the sendHttpGetRequest Action from a Rule. Or the Exec binding or executeCommandLine Action to call curl.

Like it says in the docs, the HTTP binding supports dynamic URLs. You would put for example %2$s to substitute the Item command into your URL, example

http://www.domain.org/home/lights/23871/?command=%2$s

The implication here … in your URL

[ON:GET:http://192.168.1.60:55001/UIC?cmd=%3Cpwron ...

the binding is going to try to substitute parameter %3 (and presumably fail, because there isn’t one)

You need to escape % in your URL, by doubling, e.g. %%3C

I tried to dubling all the % and just the one you said. Didn’t work.
May i missunderstand you…
Could you please give me the hole exmple for this Item:
Switch WAM350_1_Mute "Mute ist [%s]" { http="> [ON:GET:http://ip_speaker:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22on%22/%3E] > [OFF:GET:http://ip_speaker:55001/UIC?cmd=%3Cpwron%3Eon%3C/pwron%3E%3Cname%3ESetMute%3C/name%3E%3Cp%20type=%22str%22%20name=%22mute%22%20val=%22off%22/%3E] <[http://ip_speaker:55001/UIC?cmd=%3Cname%3EGetMute%3C/name%3E:30000:XPATH(/UIC/response/mute)]" }

Thx for you help

This works fine…
But its a lot more Code that it could be… but if i can fix it i will go with the rules.

My Problem is, that i like to get also the response (see above: GETMUTE), otherwise if someone mutes the Radio manually, i will be wrong with my state.
Any Idea?
This is my Rule so far
`rule “SwitchRadioMute”
when
Item WAM350_1_Mute changed from OFF to ON
then
sendHttpGetRequest(“http://192.168.1.61:55001/UIC?cmd=<pwron>on</pwron><name>SetMute</name><p%20type=“str”%20name=“mute”%20val=“on”/>”)
end

rule “SwitchRadioUnMute”
when
Item WAM350_1_Mute changed from ON to OFF
then
sendHttpGetRequest(“http://192.168.1.61:55001/UIC?cmd=<pwron>on</pwron><name>SetMute</name><p%20type=“str”%20name=“mute”%20val=“off”/>”)
end
`
My second Question is: Can use a Variable in to the http Request like this

Var VOLUME = itemValue.(DimmerXY)
http://$SPEAKER:$PORT/UIC?cmd=%3Cname%3ESetVolume%3C/name%3E%3Cp%20type=%22dec%22%20name=%22volume%22%20val=%22$VOLUME%22/%3E"

My idea is to set a Item Dimmer with the Value in HABPanel and use it directly in the Rules.
But my Syntax is that bad, as my english :rofl: :kissing:

I have a Solution, may not the best way?

    `rule "SwitchRadioVolume"
when
	Item WAM350_1_Volume received update
then
	val String httpString = ""
	val String VOLUME = ""
    VOLUME = WAM350_1_Volume.state.toString("%d")
    httpString = "http://192.168.1.61:55001/UIC?cmd=%3Cname%3ESetVolume%3C/name%3E%3Cp%20type=%22dec%22%20name=%22volume%22%20val=%22" + VOLUME
    httpString = httpString + "%22/%3E"
	sendHttpGetRequest(httpString)
end`

Better solutions? Or should i go with this…

I would create all the rules in this way, so I would rather ask now than do a lot of correction work afterwardsi

No. You’ll have to be careful, it is easy to get wrong where you have a lot of url encoded characters
http://ip_speaker:55001/UIC?cmd=%%3Cpwron%%3Eon%%3C/...

Then do so

val results = sendHttpGetRequest(“[http://192...
logInfo("test", "return " + results)

I would advise adding a timeout as well.

No. But as you have already found, it’s just a string and you can make it up from parts.

Thank you for your contribution.
How i know witch one is right and witch is worng? Some Dok? oder Try and Error :rofl:

Can I use the result to update the item or something similar?
So that I can see the updated value in HABPanel?
Or assign using MAP according to the switch?

It’s just a string. I don’t know what it is going to contain. You can do anything you like with it. If you want to use it in HABpanel, you’ll have to post it to some Item.

So I mean is there a way to assign the string to the switch as a state so that it is always “uptodate”? or is tracked?
I don’t have an idea how to do that

val results = sendHttpGetRequest(httpString, timeOut)
someItem.postUpdate(results)

It’s just a string. Often, you’ll want to process or check it in your rule before using it.

Ashes on my head.

Just had a dropout … but thanks for the patience and the answer to my stupid question.
Now I think I have everything together to get a smart integration of my speakers.

Many thanks to all of you.

1 Like

Maybe you can help me extract the answer.
I get the following answer:

<?xml version="1.0" encoding="UTF-8"?> <UIC> <method>MuteStatus</method> <version>1.0</version> <speakerip>192.168.1.61</speakerip> <user_identifier></user_identifier> <response result="ok"><mute>**on**</mute></response> </UIC>

But I only want to have the part “on” or only have something from the entire answer.
I’m unfortunately not familiar with Xpath.
I think it should look like tsomething like that?

`response= sendHttpGetRequest(http://ip_speaker:55001/UIC?cmd=%3Cname%3EGetMute%3C/name%3E:30000:XPATH(/UIC/response/mute))

myitem=postUpdate(response)`

Or should I take the entire answer and only then split it.
However, for both ways I unfortunately lack an example of how to do it.

Me neither, maybe someone else will help.

I’d cheat :wink:


if (results.contains("<mute>**on**</mute>")) {
    someSwitch.postUpdate(ON)
} else if (results.contains("<mute>**off**</mute>")) {
    someSwitch.postUpdate(OFF)
} else {
    someSwitch.postUpdate(UNDEF)  // SURPRISE
}

:rofl: :rofl: :star_struck:
Nice one…

I thin I’ll take it, until someone have a better soulution :yum: