Alexa Binding Different Behaviour Rule to UI

Hi

I’ve discovered that something that used to work prior to OH2.5 seems to no longer work as expected.

I have a rule that at 5pm everyday sends the command Echo_Living_Room_RadioStationId.sendCommand(’’), this simply tells Alexa to stop playing TuneIn radio and is as per the Binding notes. It no longer works as it generates an error

Echo_Living_Room_RadioStationId changed from s12244 to 

2020-02-25 15:50:02.948 [vent.ItemStateChangedEvent] - Echo_Living_Room_Radio changed from ON to OFF
2020-02-25 15:50:02.950 [vent.ItemStateChangedEvent] - Echo_Living_Room_Subtitle2 changed from Kitchener, ON to 
2020-02-25 15:50:06.091 [ome.event.ItemCommandEvent] - Item 'Echo_Living_Room_RadioStationId' received command 
2020-02-25 15:50:06.098 [nt.ItemStatePredictedEvent] - Echo_Living_Room_RadioStationId predicted to become 
2020-02-25 15:50:06.297 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler@6105f9': POST url 'https://alexa.amazon.ca/api/np/command?deviceSerialNumber=G0xxLF1072451R84&deviceType=A3S5BxxHU6VAYF' failed: Not Found

org.openhab.binding.amazonechocontrol.internal.HttpException: POST url 'https://alexa.amazon.ca/api/np/command?deviceSerialNumber=G0xxLF1072451R84&deviceType=A3S5BxxHU6VAYF' failed: Not Found

	at org.openhab.binding.amazonechocontrol.internal.Connection.makeRequest(Connection.java:648) ~[?:?]
	at org.openhab.binding.amazonechocontrol.internal.Connection.command(Connection.java:982) ~[?:?]
	at org.openhab.binding.amazonechocontrol.internal.Connection.playRadio(Connection.java:1046) ~[?:?]
	at org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.handleCommand(EchoHandler.java:569) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]
	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
	at com.sun.proxy.$Proxy364.handleCommand(Unknown Source) [?:?]
	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:74) [bundleFile:?]
	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]
	at sun.reflect.GeneratedMethodAccessor246.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_222]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_222]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_222]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]

However, performing the same action using the sitemap…

2020-02-25 15:54:12.068 [ome.event.ItemCommandEvent] - Item 'Echo_Living_Room_RadioStationId' received command 
2020-02-25 15:54:12.076 [nt.ItemStatePredictedEvent] - Echo_Living_Room_RadioStationId predicted to become 
2020-02-25 15:54:12.124 [vent.ItemStateChangedEvent] - Echo_Living_Room_RadioStationId changed from s12244 to 
2020-02-25 15:54:13.607 [vent.ItemStateChangedEvent] - Echo_Living_Room_Radio changed from ON to OFF
2020-02-25 15:54:13.611 [vent.ItemStateChangedEvent] - Echo_Living_Room_Player changed from PLAY to PAUSE

No error?
Anyone have any ideas for me to look at?

Could it be related to typecasting - to turn on in the morning I use Echo_Living_Room_RadioStationId.sendCommand(‘s12244’) maybe the (’’) is the thing it doesn’t like

openHab build 2.5.2 Stable

Thanks

Can we ask how, exactly? A mapped Switch with an empty string or something?

Sure, the same way as described in the Alexa binding documentation https://www.openhab.org/addons/bindings/amazonechocontrol/

Sitemap:
Selection item=Echo_Living_Room_RadioStationId mappings=[ ‘’=‘Off’, ‘s12244’=‘Radio1’, ‘s31114’=‘Radio2’, ‘s6894’=‘Radio3’, ‘s6816’=‘Radio4’ ]

Items File:
String Echo_Living_Room_RadioStationId “TuneIn Radio Station Id” (Alexa_Living_Room) {channel=“amazonechocontrol:echo:b5ffc39c:GxxxLF1072451R84:radioStationId”}

How curious that an empty string command is okay via REST API (which is how the UI sends it) but not via method .sendCommand
And it seems to be the binding that chokes on it, not core … when is an empty string not an empty string? Weird.

It is worth a try with action instead
sendCommand(Echo_Living_Room_RadioStationId, "")
because that does parse differently to method, potentially more like REST API

Thank you for the suggestion.
It didn’t work, infact I tried various other commands and they all failed. I think I have a lead though.

Part of the script I didn’t share is just before the command to switch off the radio I send a Echo_Living_Room_TTS.sendCommand(‘Its five pm…, turning the radio off’) to have Alexa say its going to switch the radio off.

I’ve had problems with speech being cut off before so I place a Thread::sleep(5000) after and before the radio off command. It seems that it is this that causes the script to fail.

Even putting the radio off before sending the announcement causes the action to fail, though interestingly without the error message, it just doesn’t do anything.

Deleting the announcement and only telling the radio to stop works fine, so it looks like some sort of Race condition with the Alexa device.

Any comments from someone that knows the Alexa API well would be appreciated.

Just one more thing, in the morning I use a similar rule

        logInfo ("Rules", "Running Radio on rule")
	Echo_Living_Room_Volume.sendCommand (35)
	Echo_Living_Room_TTS.sendCommand('Good Morning............, lets turn on the radio')
	Thread::sleep(10000)
	Echo_Living_Room_RadioStationId.sendCommand('s12244')

This works fine, the same delay in the evening doesn’t unless I turn the radio off then send the speech command

	Echo_Living_Room_RadioStationId.sendCommand('')
	Thread::sleep(10000)
	Echo_Living_Room_TTS.sendCommand('Its five pm............, turning the radio off')

That was a bit sneaky, but I doubt anyone would guess it was relevant. :smiley:

But it’s the openHAB Thing throwing the error. Certainly oddball.