How does Alexa determine what commands a device supports?

alexa

(Allan) #1

Not sure if my title is right or not. More specifically how does Alexa relay the commands to SmartThings?

Here is what I’m trying to figure out. I recently added RGB and RGBW LED support to the ST_Anything project so it can be used for lighting. The RGB for example has a standard dimmer control (capability “Switch Level”), standard on/off (capability “Switch”), and a color control (capability “Color Control”). I can do standard stuff and it works fine:

“Alexa turn on the Kitchen Cabinet Lights”: Turns then on (same with off).
“Alexa set the Kitchen Cabinet lights to 60”: Sets the dimmer to 60

So I have a bunch of commands defined in the DTH (command “red”, command “green”, etc) with buttons for them. When I say “Alexa set the kitchen cabinet lights to Green” she says “ok” but nothing happens. Normally if its a command a device doesn’t accept it says “that device doesn’t support that” or something like that. Is it trying to send “green” to the device but its getting lost? Or is it not sending anything? How can I tell?

I’m guessing it can’t figure out “green” but is it possible to send something like that over?

-Allan


(Dave Gutheinz) #2

For my lights (through SmartThings), Alexa can control colors. I have a TP-Link LB130 that is only connected to Alexa through SmartThings. I do not have color commands defined in my DTH. Instead, there is a color wheel returning six hex characters. Somewhere, the color blue is automatically converted to the correct color string for the device. Works great - and thanks SmartThings!

I think they key on Capability within SmartThings, not commands. For me, that is Capability; Color Control.


(Allan) #3

Yeah…I don’t get it. I never see a failure in logging or anything and like I said Alexa says “Ok” like it took the command. My color control converts to hex and sets the light, same as the quick commands. So if you click the “Blue” button it sends a #0000FF for blue. If you click Blue within the color picker it does the same thing.

What bulbs are you using or what DTH for them? I’ll look through it and see if I missed something.


(Dave Gutheinz) #4

The color bulb is the TP-Link LB130. I wrote the Service Manager and DTH for this and others in the link below.

TP-Link Bulbs and Plugs Control.

I also have osram lightify bulbs, but not color.


(Allan) #5

Still can’t figure out why this isn’t working. I looked at your DTH and I don’t see anything out of the ordinary. My DTH does support “Color Control” and I wouldn’t think it needs color temp.

If anyone else has any suggestions please let me know.


#6

Tagging @MichaelS


(Micheal ) #7

More than likely you will need to forget the device then rediscover it so it knows that it is a color control. However with custom DTHs it may be hit and miss.

Hope that helps.


(Allan) #8

So it should just “work” correct? Does it matter that I’m using a bunch of defined commands for the colors?

I guess the better question is how does Alexa send a command for a bulb that doesn’t specifically have color commands defined? I’m sure Alexa isn’t converting to hex so I imagine it sends “Orange” to SmartThings which sends it to the device but what it is sending? “Orange” whcih matches a command or would SmartThings be converting it and looking for something that might not be in my DTH? Like a setColor(color as map) or something that I would need to add?

Edit: DTH in question: https://github.com/vseven/ST_Anything/blob/master/devicetypes/ogiewon/child-rgb-switch.src/child-rgb-switch.groovy


(Micheal ) #9

Again if it is a custom DTH it will be a crap shoot if it works or how the colors are translated


(Allan) #10

So the question is what is being called in a “standard” DTH like Hue or Lifx? Who from SmartThings can we tag that might be able to answer?

EDIT: May have figured it out. I manually added a new bulb called “Test Color Bulb” using the LIFX Color Bulb device type. I then added it to Alexa and turned on debug. I said “Alexa set Test Color Bulb to Blue” and in logging I saw “setColor [hue:67, saturation:100]” so I’m thinking that be default “setColor” is the command it uses. Going to add that command to my DTH and just have a debug line in it and see if that is what is called.

Second Edit: Yup…setColor is what gets called with a color map which contains hue and saturation. If that doesn’t exist then apparently it doesn’t take color commands. I’ll add a setColor routine that just converts hue/sat over to a value that will go through my “normal” adjustColor routine I already have in place.

Last Edit: More testing and I’m 99% sure setColor is the “standard” way SmartThings transfers a color from Alexa/GH to a device type through the color map and not only is that name required but it has to be passed a “map color”. So the conversion seems to happen in the cloud and only the Hue/Sat is passed. I then take that and convert it to RGB then to Hex and its working great.

@jodyalbritton - Can you confirm the above? Is it documented somewhere that I missed? I.e. a list of supported color names?


Color is returned as a String when using latestValue? How to pull back out as map?
(Jody) #11

SetColor is the way but I’m not sure of the list of colors. I believe that comes from the voice provider. Maybe @Jim will know for sure


(Allan) #12

Turns out you mentioning “voice provider” gave me enough to search on:

"To set a color explicitly, add code in your skill adapter to respond to the SetColorRequest directive. The payload of the request contains a color object with Hue, Saturation, and Brightness (HSB) which maps to the color requested by the customer. "

then later in the article:

“If the target device requires Red, Green, Blue (RGB) settings, convert from HSB to RGB in the skill adapter.”

So it looks like, for Alexa at least and I’m sure google is similar, they are passing saturation and hue and SmartThings is simply relaying this information to the DTH with no conversions going on. The fact that SmartThings is not putting “brightness” in the payload might be a issue for someone but I’m using my slider control for that anyway. Which also, to me, means SmartThings is not relaying that piece of information.

I then tried something that was in the article:

“Alexa, set cabinet lights to daylight”

and Alexa reported back the cabinet lights don’t support that. Which is right because in my DTH I did not add in “capability.colorTemperature”.

Gonna add in that capability and see if the correct color temperature is then passed through and will report back. (Edit: it worked just fine. Asked Alexa to set the lights to soft white and got a “2700” to the setColorTemperature routine)

Since SmartThings is getting just the hue/sat/brightness (and seems to be ignoring brightness) then that means the color list is on Alexa or Googles side which I can’t find a list yet but it could be anything they feel like supporting.

@Jim - Can you confirm the above? Also can you confirm you are not accepting brightness from Alexa/Amazon even though it is in their payload? And if you can confirm that is there a reason you aren’t or is it because you assume a slider control to take care of that part?


(Jim Anderson) #13

Would need someone from the engineering team working with Alexa to confirm how it handles voice commands specifically. But for SmartThings, the setColor([hue: xx, saturation: yy]) command of the Color Control capability is correct.