[SOLVED] Set an arbitrary string with Alexa

I have this problem: I’d like to set the TV channel on my Kodi mediaplayer using the OpenHAB skill for Alexa (it’s up and running on my installation, I can turn items ON and OFF). Unfortunately the ChannelController capability is not currently supported for my country (Italy), so I’m looking for an alternate way.

I created a switch with some channels I like:
Switch item=tvchannel label=“Channel” mappings=[SKYTG24=“SKY TG24”, TGCOM24=“TGCOM24”, RAISTORIA=“RAI Storia”] icon=“screen”

When I tap a button, it sets the string “tvchannel” to the selected value, then a rule sends the correct HTTP command to Kodi and the channel is played on the TV.

I would like Alexa to do the same thing, but how can I send a command to a switch that has arbitrary state strings instead of ON/OFF? I tried to say “Alexa, set channel to Sky TG24” but it simply doesn’t work. It seems that sending custom values to OpenHAB string items is impossible using the Alexa skill, it works only with exact values (like with the cooling modes: OFF, ON, AUTO…).

Thank you very much for your help.

You could create a item for each channel and switch them ON

If you are in the US, you could use the ModeController to achieve this: (Actually, after re-reading your post, I missed the part that you are located in Italy, so this solution is just for reference purpose)

String tvchannel "TV Channel" {alexa="ModeController.mode" [friendlyNames="Channel", supportedModes="SKYTG24=SKY TG24,TGCOM24=TGCOM24,RAISTORIA=RAI Storia”]}

Otherwise, you will have to create separate activities, part of a group, for each channel as @Vradatta mentioned above. These would be limited to only turn on.


Group gTVChannels "TV Channels"
Switch TVChannelSKYTG24 "SKY TG24" (gTVChannels) {alexa="Activity" [supportsDeactivation=false]}
Switch TVChannelTGCOM24 "TGCOM24" (gTVChannels) {alexa="Activity" [supportsDeactivation=false]}


rule "TV Channels"
  Member of gTVChannels received command ON
  val channelName = transform("REGEX", "TVChannel(\\w+)", triggeringItem.name)

Last but not least, you have to be careful how you are naming your channels. In some cases, Alexa may not always translate complex names the way you might want.

Thank you very much for your nice workaround: the group is a good way to have a quite simple rule.

The only ugly aspect is that I will have to say “Alexa, turn on Sky TG24” (in italian will be "Alexa, accendi Sky TG24) instead of “Alexa, metti su Sky TG24” (I’m not sure about the english phrase… maybe “Alexa, tune in to Sky TG24”?) that would be the natural language to this sort of activity… but not so important :slight_smile:

Unfortunately, there is no way around that. You have to request an activation.

Alexa, turn on <activity>
Alexa, switch on <activity>
Alexa, activate <activity>
Alexa, enable <activity>
Alexa, <activity> on