Aircoookie / Espalexa

Alexa voice control for ESP8266/ESP32 (including brightness and color!)
MIT License
540 stars 134 forks source link

Color support not working with Echo Dot 2 #28

Open d-999 opened 5 years ago

d-999 commented 5 years ago

Hey there, so I tested the new color support. Unfortunately it's not quite working for me, I didn't try too long, so it may be my fault. When I upload the EspalexaColor example sketch and try to change the color Alexa states my device doesn't support that. I first assumed, since I live in Germany, maybe Alexa in German doesn't support Color yet, according to the Internet however, I believe it should be supported. Besides Alexa says my device doesn't support it, not that she doesn't support it. I confirmed that I'm in fact using the new library and I do get a color value over the serial Port, RGB: 237, 255, 239 which I considered a somewhat odd default color. Anyway, any thoughts on what might be the cause or what I could try?

Aircoookie commented 5 years ago

Hi, thanks for the feedback! Weird that the color support didn't yet work for you. I live in Germany too, so I don't believe we have a location issue here.

Did you attempt deleting the device in the Alexa app and re-discovering it? It might be that Alexa still recognizes it as a dimming-only device, especially if you had an Espalexa device with the same name and/or on the same ESP before the update.

RGB 237, 255, 239 may be the result of the conversion formula for Hue = 0 and Saturation = 0. The library uses Hue + Saturation and Color Temperature internally. If you create the device yourself colorLight = new EspalexaDevice(colorLightChanged), you have additional methods to access them like colorLight.setColor(hue, sat), colorLight.getSat() and colorLight.getHue().

d-999 commented 5 years ago

Hey there... Yes, I tried deleting the device and giving it a name I hadn't used before, to insure Alexa isn't mixing things up. I'm not sure how we could ideally debug this behavior. I guess we can rule locations differences out. And since Alexa says my device doesn't support it, rather that trying to send color data and failing the only debugging information I get is during discovery. In case you wanna take a look, here it is:

Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 15
ST: urn:schemas-upnp-org:device:basic:1

Responding search req...
# Responding to description.xml ... #

Sending :<?xml version="1.0" ?><root xmlns="urn:schemas-upnp-org:device-1-0"><specVersion><major>1</major><minor>0</minor></specVersion><URLBase>http://192.168.10.17:80/</URLBase><device><deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType><friendlyName>Philips hue (192.168.10.17)</friendlyName><manufacturer>Royal Philips Electronics</manufacturer><manufacturerURL>http://www.philips.com</manufacturerURL><modelDescription>Philips hue Personal Wireless Lighting</modelDescription><modelName>Philips hue bridge 2012</modelName><modelNumber>929000226503</modelNumber><modelURL>http://www.meethue.com</modelURL><serialNumber>5ccf7f115d7d</serialNumber><UDN>uuid:2f402f80-da50-11e1-9b23-5ccf7f115d7d</UDN><presentationURL>index.html</presentationURL><iconList>  <icon>    <mimetype>image/png</mimetype>    <height>48</height>    <width>48</width>    <depth>24</depth>    <url>hue_logo_0.png</url>  </icon>  <icon>    <mimetype>image/png</mimetype>    <height>120</height>    <width>120</width>    <depth>24</depth>    <url>hue_logo_3.png</url>  </icon></iconList></device></root>
Not-Found HTTP call:
URI: /api/27yZWOg5pHKP8uPFoNkN7YdJMsWI7swI8idp8LJE/lights
Body: 
AlexaApiCall
ok
l0
lAll
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 5
ST: urn:schemas-upnp-org:device:avm-aha:1

Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 5
ST: urn:schemas-upnp-org:device:avm-aha:1

Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 5
ST: urn:schemas-upnp-org:device:avm-aha:1

Not-Found HTTP call:
URI: /api/27yZWOg5pHKP8uPFoNkN7YdJMsWI7swI8idp8LJE/lights/1
Body: 
AlexaApiCall
ok
l1

I assume some of the UDP connections are from my router or other devices in my network. Unfortunately if I tell Alexa to change the color, she doesn't send any data. If I tell her to turn the device on/off or change the brightness I get the usual ApiCalls with {"on": true}, {"on": false} or {"on": true,"bri":127} for example but nothing particularly interesting really. So yeah, if you can think of any way to get more information, let me know. About the color, strangely I now get RGB 255, 255, 255 and can't reproduce the result I had before, getSat() and getHue() return 0, unfortunately I don't know what the Sat and Hue was before, when I got different results. The last thing I can think of, is my phrasing to be incorrect. Usually Alexa accepts pretty much anything you throw at her and I've tried many formulations. And I would expect her to understand something simple like "Alexa, stelle <Gerätename> auf Rot." or whatever. But if you want you can give me an example phrase you know works... Anyway, that's pretty much all I know so far.

Aircoookie commented 5 years ago

Thank you for the testing! Strange that you get RGB 255, 255, 255 now (well, rather that there was a different value before, although I also had 237, 255, 239 as default). If i initialize both hue and sat to 0 this issue should vanish.

If you don't get any API calls like {"hue":20000,"sat":254}, that means Alexa is not even trying to set the color, so she must believe that it is a dimmable-only device somehow.

Just for the record, which Alexa model do you have? I used an Echo 2 for testing this feature (there have been implementation differences between Echo and Echo Dot models before)

There is a debug method colorLight.isColorDevice(). You can try that, if it returns false, we know it's a library fault. Your phrasing is absolutely correct. Exactly the same command works for me.

Thanks again for helping me find out why this isn't working yet! :)

Aircoookie commented 5 years ago

Also, you could try if setting for example colorLight.setColor(200, 254); in the end of setup() changes anything somehow...

Aircoookie commented 5 years ago

Totally forgot, if you go to [esp-ipaddress]/api/test/lights/1 you get the API response that is sent to Alexa. It should look something like:

{"type":"Extended color light","manufacturername":"OpenSource","swversion":"0.1","name":"Lampe","uniqueid":"30:AE:A4:1C:A7:3C-2","modelid":"LST001","state":{"on":true,"bri":128,"xy":[0.00000,0.00000],"colormode":"hs","effect":"none","ct":500,"hue":0,"sat":254,"alert":"none","reachable":true}}

d-999 commented 5 years ago

Well, it's in both our interests to get the library running (assuming it is in fact the libraries fault). So thanks for writing the library and trying to help me figure it out. So, colorLight->isColorDevice() returns 1, colorLight->setColor(200, 254) sets the color to RGB: 255, 5, 0 with no additional effect, /api/test/lights/1 returns the following JSON object:

{"type":"Extended color light","manufacturername":"OpenSource","swversion":"0.1","name":"Apfel","uniqueid":"5C:CF:7F:11:5D:7D-2","modelid":"LST001","state":{"on":true,"bri":127,"xy":[0.00000,0.00000],"colormode":"hs","effect":"none","ct":500,"hue":200,"sat":254,"alert":"none","reachable":true}}

I'm using an Echo Dot 2, I would assume the problem is either, that Alexa for some reason doesn't consider the device a color device and therefore doesn't try to send color data or that my Echo Dot for some reason doesn't support color devices yet. It's about 1.5 years old, so maybe it needs a software update? I don't know, do you need to update Alexa manually? She replies specifically with "Apfel unterstützt das nicht" or "Ich weiß nicht wie ich diese Einstellung für Apfel machen kann". Yes I know, apple is a stupid name, but it's the first thing I could think of that's definitely not gonna conflict with any other device names. Anyway, if you have any further suggestions feel free to suggest.

Apart from that, I've been trying to figure out the ESPAsyncWebServer problem, with no success so far. I couldn't find any way so far to get the library to return the raw request data without modifying it. It's kinda annoying since it's such a trivial problem. I'm not 100 %, that is in fact the problem, but given that Alexa finds the device and the ESP reacts to state changes, but it doesn't get any body data and therefore doesn't change the state. But I guess we should talk about that in the corresponding issue, as not to confuse people...

Aircoookie commented 5 years ago

Ok, your JSON object and method return values both seem valid. I just tried deleting the device and then discovering it with my Echo Dot 2 (fortunately i have both) and it worked without problems, full color support. I'll try again with the big Echo unplugged to verify though. I just pushed 2.2.1, because sporadically the discovery process would fail for me, so I updated the response to mimic the actual hue bridge behavior a tiny bit more closely. I don't believe that is related to this issue, though.

You could try to delete and discover the device in the Alexa app itself (select discover hue light). After it has been discovered successfully, go to its control page in the app and select the cog icon. I'm curious to see if it actually reports "Color Capabilities: None", which would be really weird. For the record, my About section says:

Connected Via: Hue Hub / Description: Royal Philips Electronics intelligentes Gerät / Type: Light / Color Capabilities: Color, Color Temperature

About ESPAsyncWebServer, you are right, I will respond to you in that issue.

Aircoookie commented 5 years ago

About the software, Echo devices always update automatically, there isn't even an option for manually updating them. However, you can see the installed version in the app if you go to Devices -> Echo & Alexa -> [Echo Name] ->About (scroll way down). The version of my Echo Dot 2 is apparently 628538320 while the version of the Echo Plus is 628538220 and the Echo 2 618622620. So, since my three devices all have different versions and the color capability over the local API was only introduced with a recent update (i first noticed on the 20th of December that color seems to be supported), it might be that Amazon has not yet rolled it out for your Echo... (which would certainly be quite sad)

Aircoookie commented 5 years ago

Alright, I did some more testing. First of all, don't bother with v2.2.1. It seems to make discovery issues even worse than with 2.2.0.

So, I unplugged the big Echos and just let the Echo Dot discover - which it did, and I could reproduce the issue! I'm getting

Type: Light Strip / Color Capabilities: None

and, after plugging the Echo 2 back in, even it reports "Lampe unterstützt das nicht" until I re-discover it. Then, "Schalte Lampe auf Grün" works, even with the Dot.

So, it seems like the color support doesn't work with the current Dot 2 firmware. We just need to hope that Amazon adds the capability soon... I'm sorry, I don't think there is anything I can do to make the color feature work for you at this time :(

d-999 commented 5 years ago

Hey, thanks for all your troubleshooting... Wow, that's interesting. So apparently when there's at least one newer Echo in the network it works huh? Well that's fine, I guess they'll probably roll out updates for the Echo Dot 2 eventually. I also don't really need color support right now. Most important to me is the brightness control, so your library is still very useful for me! Anyway, thanks for (most likely) solving the riddle. I'll let you know if and when it eventually works on the Echo Dot 2 in my case.

Aircoookie commented 5 years ago

Thank you! Have fun with the library and let's hope we can get the async server working soon!

d-999 commented 5 years ago

Thanks... :-) Oh and I forgot to mention, the software version of Echo Dot 2 is exactly the same as yours.

d-999 commented 5 years ago

Hey, I just wondered. Did you also try disconnecting the other Echos and running the original hue bridge only on the Echo Dot 2 to see if it also doesn't support color then (assuming you have original phillips lights with color support)? That way we could confirm it's not the library that for some reason only works on certain Echos but it's in fact the Echo Dot 2 that doesn't support it (yet).

Aircoookie commented 5 years ago

Hey, no I did not try that recently, because it would delete all my custom hue group names. However, when I first got Hue color lights a year ago I tried it with the following results:

So, at that time, no, color support wasn't working with the official device via the local API. I assume they now changed this (at least for the big Echo) and that's why it is also working in Espalexa now, however I can't verify that easily, sorry.

d-999 commented 5 years ago

Ok, so I've been reading a bit online. And it seems as though some people do have color support with Echo Dot 2. However, I assume probably not over the local API which Espalexa uses and apparently some people also have been having trouble with the colors sometimes working and sometimes not. Anyway, on Amazon's website itself, there is a page about it here. And it does in fact say "Hinweis: Die grundsätzliche Funktionen „ein“, „aus“ und „dimmen“ ist ohne die Philips Hue Skill verfügbar und ist mit Philips Hue V1 (rund) und V2 (quadratisch) Bridge kompatibel." which sounds like color support over the local API shouldn't be available at all. Though of course it's possible that article isn't up to date or they just didn't want to make it unnecessarily complicated. Either way, assuming they will eventually push an update for the Echo Dot 2, I guess we don't really have to worry about it anyway.

Salomon-MH commented 5 years ago

I can reproduce the behavior on my Echo Dot 1 (Germany), so it's not an 2 specific issue. It also shows as

Type: Light Strip / Color Capabilities: None

for me. Weird.

I do not have the Hue skill activated though, as I do not have an account for that. Is that needed?

Aircoookie commented 5 years ago

As of firmware version 628568520 color is now supported on my Echo Dot 2 (Germany). However, the content type bug (sending application/x-www-form-urlencoded instead of application/json) is still present, unfortunately, requiring the usual workaround (#6 for ESP8266)

d-999 commented 5 years ago

Oh hey thanks, I hadn't tried using color in a while. But you're right my Echo Dot 2 (Germany, running firmware version 635560020) also supports color over the local API now. Too bad they didn't fix the content type error yet (I wonder if they even realize it's there...?). But you know, the current workaround isn't super complicated and it works, so I guess it's something one can live with. One could potentially add a #ifdef to enable/disable the workaround or normal code so the ESP doesn't have to process both each time. But that would be less convenient for the user and I doubt it would make a noticable difference in performance, so I guess the current solution is probably the best.

d-999 commented 5 years ago

P.S. After playing around with colors a little, I found that color temperature still doesn't work. I didn't investigate this, but I suspect the Echo Dot 2 while supporting color now, still doesn't support color temperature.

Aircoookie commented 5 years ago

Yes, that is correct, color temparature is not supported on Dots. Don't worry, the workaround doesn't really cause overhead for the ESP, so adding a toggle would make little sense. My goal is it to have this library work for every Echo model and the user shouldn't have to worry about how it achieves that :)

d-999 commented 5 years ago

Yeah, that's what I thought too (about the workaround), it wouldn't make any noticeable difference but would make the library more complicated to use and confusing for people who are just getting started with Arduino/programming. About color temperature, you say color temperature is not supported on Dots... Does that mean it is supported on Echos (not Echo Dots)? That would be kinda strange. Anyway, too bad it's not supported. Color temperature support would probably be more useful to me than color support. :D But thanks for the clarification.

Aircoookie commented 5 years ago

Yeah, I agree, there are many occasions where color temperature is really useful! That's right, it is in fact supported by (big) Echos (they also use a different method for "standard" color support and don't require the workaround, it is a bit of a nightmare that Amazon implemented it so differently on various Echo models)

buegelbeatz commented 7 months ago

I did the ssdp implementation in micropython and I can set the color and the white-value. I want to share my observations: 1.) Don't use german Umlaute for namings ;-) 2.) If 'on' key has the value true in your payload you should check if the state.bri is greater 0 otherwise you get on/off effects - so if state.bri is not set or 0 and state.on = true set state.bri to 100 3.) if hue and sat key has values in your payload set state.colormode = 'hs' ; if ct key has a value set state.colormode = 'ct'

and 4.) I don't test it, but I would expect if x and y keys are used set state.colormode = 'xy'