aircoookie / espalexa Goto Github PK
View Code? Open in Web Editor NEWAlexa voice control for ESP8266/ESP32 (including brightness and color!)
License: MIT License
Alexa voice control for ESP8266/ESP32 (including brightness and color!)
License: MIT License
Is there an option to turn off the internal (blue) LED of the ESP8266 on my NodeMCU?
Hi Aircookie,
this is great and works perfect for me - I like the feature of being able to respond to a "dimming" value a lot.
Only thing IΒ΄m currently missing is the support for more then one device - right now I have no real clue I to add that.
Would you be able to provide an extension to more than one device?
Thanks for your work - MacSass
ESPAlexaBasic, Compiled for a Wemos D1 Mini with Arduino 1.8.4, ESP8266 2.3.0, and a freshly-downloaded copy of ESPAlexa. Echo Dot 2nd Gen, Android Alexa app version 1.24.203566.0
The Echo Dot was purchased last Black Friday, and has the problem of not recognizing fauxmo devices because it needs the Wemo skill to use them.
Discovery fails on both the app and the Echo. No SSDP discovery messages are being sent (I have a Linux app that watches the WiFI for them). The ESP8266 does respond correctly to an M-SEARCH broadcast from a Linux app, and returns what looks like a good description.xml.
I tried to enable the Hue skill, but that failed during account linking because I don't have a real Philips device. Is this necessary for the sketch to work?
I'm seeing the same problem with Xose's 3.0.0 version of fauxmo, which also uses the Hue protocol. Is this a result of the Alexa software changes that screwed up lots of emulators?
Hey,
is it possible to get HSV value instead of RGB?
For this function:
espalexa.addDevice("Light", colorLightChanged);
[...]
void colorLightChanged(uint8_t brightness, uint32_t rgb) { [...] }
i need RGB, but for my next step i need HSV in my function.
I think a RGB->HSV-conversion is a bad idea because Alexa tell Espalexa hue|sat|bri|ct π
Thank you π
In Alexa app, I am seeing Color device has both Color Capabilities. So current implementation support Colors device, but it includes both color capabilities. This should be separated to:
Most general LED lighting products support color temperature change only. RGB control is for special lighting purpose only and the use is not that many. (I am working in lighting field, so I know this well)
So please add at least one device type for color temperature control only.
Hello,
Currently have your code implemented to control the opening of some blinds. However, I want a way to add a button in so I can change some sort of 'Mode' so that I can then use another two buttons for manual control. Then when the button is pressed again, it goes back to using Alexa. I was just wondering if this is possible?
Even better would be to eliminate the mode buttons and just have two buttons which can directly override anything. If you could help that would be great!
Many Thanks
Jamie
Hi, all.
Is it possible to have a function, that user can configure the devices name by theirself use the webpage instead of change the code than compile and flash.
Please Add setName to ExpalexaDevice
Please Add removeDevice to Espalexa
I would like to control a Lutron infrared-controlled-only dimmer switch. However, I think I have reached an impasse. While experimenting with this code's dimmer capable device type I realized that the dimmer numbers jumped so much that after about 3 dimmer "turn up" commands the absolute dimmer setting is at its maximum. I had assumed each dimmer "turn up" or "turn down" command would only change the absolute dimmer setting by 1. True, I may exhaust the code's dimmer range before exhausting the Lutron dimmer range. But it would be a start.
Alternatively, is there a way I can continuously reset the dimmer setting to 50%. Then, any dimmer "turn up" command would result in a number greater than 50%. And any dimmer "turn down" command would result in a number less than 50%. This would be ideal as the code's dimmer range would never reach a limit thereby ensuring the limit on the Lutron dimmer will be reached.
Using the latest library built under 8266 2.4.0 running the basic example telling Alexa to turn ON or OFF from a Dot gen2 only produces an ON response in the serial output. Also looking at the brightness variable it does not change including when you give Alexa the specific command to change it, i.e. 75%.
On a previous issue although the discovery process now works on the basic example in testing the webserver example the discovery process does not complete.
Thanks.
ESP32 discovery problem is still there with device supporting Color.
When using example, EspalexaColor.ino
, I never get color device discovered once!
The this is the log after discovery:
Connecting to WiFi
Connecting.............
Connected to xxx
IP address: 192.168.2.134
Constructing device 1
Adding device 1
Espalexa Begin...
MAXDEVICES 10
Done
And after 30 seconds or more, I saw there were more log suddenly appended to the above while I did not do anything. More similar messages will appear later.
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
MAN: "ssdp:discover"
MX: 2
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: urn:schemas-upnp-org:service:WANIPConnection:1
MAN: "ssdp:discover"
MX: 2
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: urn:schemas-upnp-org:service:WANPPPConnection:1
MAN: "ssdp:discover"
MX: 2
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: upnp:rootdevice
MAN: "ssdp:discover"
MX: 2
Responding search req...
PS: There is no problem for ESP8266, and Alexa app still works with ESP8266 color device.
Have you thought about creating a library with the minimum code necessary to add it to other projects?
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?
Using the basic example supplied in the library.
All devices are setup correctly and show as described in the no discover section of the readme.
Built using 8266 versions 2.3.0, 2.4.0-rc2, and 2.4.0 with still no discovery.
The network contains a mix of Gen1 and Gen2 Echo's/Dots.
There are messages on the serial port but none seem to be related to the new device definitions.
I do not have a Hue bridge and the Alexa Hue skill does not seem to be able to be installed without a bridge so is it required to have this in order for the API to be accessed and discovery to complete?
Thanks.
First of all thanks to the author(s) of this code: it seems simple to use and even works!
I tested the sample code with esp8266 and it works with the combination of "v2 higher bandwidth" and esp board 2.5.0 beta 2, while with beta 3 I've got a compilation error.
So for esp8266 no problem.
I then tried with an esp32 and I've got this error:
C:\Users\roberto\Documents\arduino librerie\libraries\Espalexa-master\src/Espalexa.h:40:94: fatal error: WebServer.h: No such file or directory
compilation terminated.
Any idea?
thanks again
Mentions of recommendations to not use delay() with Async:
So I searched for a way to control my ESPs with an Alexa device, but as I wanted to try this out my Alexa just couldn't find my device.
To be clear, it is an Wemos D1 mini "knock-off", so an esp8266 combined with an Alexa Echo Dot v2.
Hear is the output of the ESP after trying to find it 3 times:
Connecting to WiFi
Connecting.....
Connected to Fuchsbau
IP address: 192.168.188.32
Constructing device 1
Adding device 1
Espalexa Begin...
MAXDEVICES 1
Done
And yes it is connected (output of /espalexa):
Hello from Espalexa!
Value of device 1 (TestLight): 0
Free Heap: 46352
Uptime: 1213997
Espalexa library v2.3.3 by Christian Schwinne 2019
I used the recent version of the library and the esp core v2.5.0. Both devices are defenitely on the same network.
The sketch is the same as the example color sketch, I just changed the ssid and password.
Hi @aircookie, I build a new light using latest version 2.3.2 and on my echo dot gen 2 saying "set light to green" or any color does not work. I have a HUE color And it does work Fine but not with the your library.
Is that normal ? On the serial monitor I can see that when i set the light to on i get all colors values as 255.
The only difference i see against my HUE lamp is that yours is a light strip And the original lamp is a color lamp...
Ideas ?
I've updated esp32 arduino core and now it is correctly compiled.
But as opposite to the esp8266, discovery doesn't find any device.
I tried changing cpu frequency to 240Mhz, before at lower speed the board was continuously resetting, but no way to fiìnd the devices.
I added debug and this is the log:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10088
load:0x40080400,len:6380
entry 0x400806a4
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
Connecting to WiFi
Connecting.....[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.168.1.6, MASK: 255.255.255.0, GW: 192.168.1.1
.
Connected to Vodafone-roberto
IP address: 192.168.1.6
Constructing device 1
Adding device 1
Constructing device 2
Adding device 2
Adding device 3
Espalexa Begin...
MAXDEVICES 10
Done
Got UDP!
NOTIFY * HTTP/1.1
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age=100
LOCATION: http://192.168.1.250:49152/description.xml
NT: urn:schemas-wifialliance-org:service:WFAWLANConfig:1
NTS: ssdp:alive
SERVER: Linux/2.6.36, UPnP/1.0, Portable SDK for U
any suggestion?
thanks
Originally posted by @robademar in #40 (comment)
/*
This is a basic example on how to use Espalexa with 3 sections on 1 FastLED LED Strip
- first start: LED orange indicates: connect to me ;)
- LED switches to green if youre connected and configured wifi and Espalexa is in your wlan
- then LED fades to black and its ready
- otherwise LED will be switches to red and reset itselfes
*/
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <Espalexa.h>
#include <FastLED.h>
#define DATA_PIN D4
//#define CLOCK_PIN ?
#define NUM_LEDS 15
CRGB leds[NUM_LEDS];
uint8_t bri3 = 0; // Stored Values to fade Light 3
uint8_t r3 = 0;
uint8_t g3 = 0;
uint8_t b3 = 0;
//callback function prototype
void colorLightChanged1(uint8_t brightness, uint32_t rgb);
void colorLightChanged2(uint8_t brightness, uint32_t rgb);
void colorLightChanged3(uint8_t brightness, uint32_t rgb);
Espalexa espalexa;
void setup()
{
// Uncomment/edit one of the following lines for your leds arrangement.
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
for ( int i = 0; i <= 30; i++ ) { // fade from black to orange
fill_solid( leds, NUM_LEDS, CRGB(i,round( (i / 1,5) ),0));
FastLED.show();
delay(20);
}
Serial.begin(115200);
Serial.println("connect to Espalexa and configure wifi");
WiFiManager wifiManager;
if (!wifiManager.autoConnect("Espalexa")) {
fill_solid( leds, NUM_LEDS, CRGB(255,0,0)); // red
FastLED.show();
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
} else {
for ( int i = 0; i <= 30; i++ ) { // fade from orange to green
fill_solid( leds, NUM_LEDS, CRGB((30-i),(20+i),0));
FastLED.show();
delay(33);
}
Serial.println("connected to WIFI..");
espalexa_addDevices();
espalexa.begin();
delay(1000);
FastLED.show();
for ( int i = 50; i >= 0; i-- ) { // fade from green to black
fill_solid( leds, NUM_LEDS, CRGB(0,i,0));
FastLED.show();
delay(20);
}
}
Serial.println("Now it's time to ask alexa to discover devices...");
}
void loop()
{
espalexa.loop();
delay(1);
}
void espalexa_addDevices() { // add Devices you want
espalexa.addDevice("Light 1 instant", colorLightChanged1);
espalexa.addDevice("Light 2 wipe", colorLightChanged2);
espalexa.addDevice("Light 3 fade", colorLightChanged3);
Serial.println("devices added");
}
//the color device callback function has two parameters
void colorLightChanged1(uint8_t brightness, uint32_t rgb) {
float r = ((rgb >> 16) & 0xFF);
float g = ((rgb >> 8) & 0xFF);
float b = (rgb & 0xFF);
int rd = round( r / 255 * brightness );
int gd = round( g / 255 * brightness );
int bd = round( b / 255 * brightness );
Serial.print("Light 1: Brightness: "); Serial.print(brightness); Serial.print("\tRed: "); Serial.print(r); Serial.print("\tGreen: "); Serial.print(g); Serial.print("\tBlue: "); Serial.print(b); Serial.print("\tDimmed Red: "); Serial.print(rd); Serial.print("\tGreen: "); Serial.print(gd); Serial.print("\tBlue: "); Serial.println(bd);
for ( int i = 0; i <= 4; i++ ) // switch LED 0 to 4 (5 pieces) to different color/brightness NOW
leds[i] = CRGB(rd,gd,bd);
FastLED.show();
}
void colorLightChanged2(uint8_t brightness, uint32_t rgb) {
float r = ((rgb >> 16) & 0xFF);
float g = ((rgb >> 8) & 0xFF);
float b = (rgb & 0xFF);
int rd = round( r / 255 * brightness );
int gd = round( g / 255 * brightness );
int bd = round( b / 255 * brightness );
Serial.print("Light 2: Brightness: "); Serial.print(brightness); Serial.print("\tRed: "); Serial.print(r); Serial.print("\tGreen: "); Serial.print(g); Serial.print("\tBlue: "); Serial.print(b); Serial.print("\tDimmed Red: "); Serial.print(rd); Serial.print("\tGreen: "); Serial.print(gd); Serial.print("\tBlue: "); Serial.println(bd);
for ( int i = 5; i <= 9; i++ ) { // wipe LED 5 to 9 slowly
leds[i] = CRGB(rd,gd,bd);
FastLED.show();
delay(20); // Attention! delay() is a bad idea and will block the whole process!
}
}
void colorLightChanged3(uint8_t brightness, uint32_t rgb) {
float r = ((rgb >> 16) & 0xFF);
float g = ((rgb >> 8) & 0xFF);
float b = (rgb & 0xFF);
float rd = round( r / 255 * brightness );
float gd = round( g / 255 * brightness );
float bd = round( b / 255 * brightness );
float rn, gn, bn;
Serial.print("Light 3: Brightness: "); Serial.print(brightness); Serial.print("\tRed: "); Serial.print(r); Serial.print("\tGreen: "); Serial.print(g); Serial.print("\tBlue: "); Serial.print(b); Serial.print("\tDimmed Red: "); Serial.print(rd); Serial.print("\tGreen: "); Serial.print(gd); Serial.print("\tBlue: "); Serial.println(bd);
for ( int j = 0; j <= 255; j++ ) { // fade color
rn = ( rd - r3 ) / 255 * j + r3; // ugly code i know :(
gn = ( gd - g3 ) / 255 * j + g3; // but for me: nice and smooth effect ;)
bn = ( bd - b3 ) / 255 * j + b3;
for ( int i = 10; i <= 14; i++ ) { // fade LED 10 to 14 (5 pieces) to different color/brightness slowly
leds[i] = CRGB(rn,gn,bn);
}
FastLED.show();
delay(1); // Attention! delay() is a bad idea and will bloc the whole process!
}
bri3 = brightness; // store new values to fade LED later
r3 = rd;
g3 = gd;
b3 = bd;
}
Does the Philips API allow the button function to open the door lock?
thank you.
Correct me if I'm wrong, but it's not using "round", it's just cutting decimals OFF and adding 1 to the result ?
I'm actually needing to go back to 0-100 values and that's what I found, am I right ?
Thanks !
Used basic sketch. WiFi connection completed, and sub page shows 3 devices. UPnP is enabled. Echo Dot Gen1, in the U.S. Alexa app does not discover new devices.
Serial with debug:
Connecting to WiFi
Connecting........
Connected to Raptor17
IP address: 192.168.1.140
Constructing device 1
Adding device 1
Constructing device 2
Adding device 2
Adding device 3
Espalexa Begin...
MAXDEVICES 10
Done
Got UDP!
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
MAN: "ssdp:discover"
MX: 2
Got UDP!
NOTIFY * HTTP/1.1
HOST: 239.255.255.250:1900
CACHE-CONTROL: max-age=100
LOCATION: http://192.168.1.113:49153/nasdevice.xml
NT: upnp:rootdevice
NTS: ssdp:alive
SERVER: Linux/3.2.26, UPnP/1.0, Portable SDK for UPnP devices/1.6.6
X-User-Agent: redson
HTTP Req espalexa ...
sub page:
Hello from Espalexa!
Value of device 1 (Light 1): 0
Value of device 2 (Light 2): 255
Value of device 3 (Light 3): 128
Free Heap: 220632
Uptime: 29790
Espalexa library v2.3.2 by Christian Schwinne 2019
Any help greatly appreciated.
Hi, I've installed your library on 2 ESP's at the same time and Alexa discovers one perfectly fine, but when I turn the second ESP on, the devices are being renamed with the new ESP devices, instead of adding them as new one's.
An example:
ESP #1: Dev0 = TV
ESP #2: Dev0 = Amplifier
Alexa will discover TV first, and when I turn on the ESP #2, it will replace TV with Amplifier.
I think this is related with the devices ID's, any easy way to fix it ? Or should I use DEV0, DEV1 in ESP #1 and DEV 2, DEV3 in ESP #2 and that's the only way.
By the way, this does not happen on the FauxmoESP library, each device is related to the IP I think, so you can have 2 or 3 ESP's without issues of conflicting.
Thanks !!!!
Hi, SORRY... me again, got very excited with this library π
What about adding HUE color support ? So that we could get a "Alexa, set Desk Light to Red" ? Possible ?
Thanks again.
I would like to know if this firmware makes your esp a lightbulb or a hub to control the lights?
/*
This is a basic example on how to use Espalexa with FastLED LED Strip
- first start: LED orange indicates: connect to me ;)
- LED switches to green if youre connected and configured wifi and Espalexa in your wlan
- then LED fades to black and its ready
- otherwise LED will be switches to red and reset itselfes
*/
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <Espalexa.h>
#include <FastLED.h>
#define DATA_PIN D4
//#define CLOCK_PIN ?
#define NUM_LEDS 15
CRGB leds[NUM_LEDS];
//callback function prototype
void colorLightChanged(uint8_t brightness, uint32_t rgb);
Espalexa espalexa;
void setup()
{
// Uncomment/edit one of the following lines for your leds arrangement.
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
for ( int i = 0; i <= 30; i++ ) { // fade from black to orange
fill_solid( leds, NUM_LEDS, CRGB(i,round( (i / 1,5) ),0));
FastLED.show();
delay(20);
}
Serial.begin(115200);
Serial.println("connect to Espalexa and configure wifi");
WiFiManager wifiManager;
if (!wifiManager.autoConnect("Espalexa")) {
fill_solid( leds, NUM_LEDS, CRGB(255,0,0)); // red
FastLED.show();
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
} else {
for ( int i = 0; i <= 30; i++ ) { // fade from orange to green
fill_solid( leds, NUM_LEDS, CRGB((30-i),(20+i),0));
FastLED.show();
delay(33);
}
Serial.println("connected to WIFI..");
espalexa_addDevices();
espalexa.begin();
delay(1000);
FastLED.show();
for ( int i = 50; i >= 0; i-- ) { // fade from green to black
fill_solid( leds, NUM_LEDS, CRGB(0,i,0));
FastLED.show();
delay(20);
}
}
Serial.println("Now it's time to ask alexa to discover devices...");
}
void loop()
{
espalexa.loop();
delay(1);
}
void espalexa_addDevices() { // add Devices you want
espalexa.addDevice("Light", colorLightChanged);
Serial.println("devices added");
}
//the color device callback function has two parameters
void colorLightChanged(uint8_t brightness, uint32_t rgb) {
float r = ((rgb >> 16) & 0xFF);
float g = ((rgb >> 8) & 0xFF);
float b = (rgb & 0xFF);
int rd = round( r / 255 * brightness );
int gd = round( g / 255 * brightness );
int bd = round( b / 255 * brightness );
//do what you need to do here, for example control RGB LED strip
Serial.print("Brightness: ");
Serial.print(brightness);
Serial.print("\tRed: ");
Serial.print(r); //get red component
Serial.print("\tGreen: ");
Serial.print(g); //get green
Serial.print("\tBlue: ");
Serial.print(b); //get blue
Serial.print("\tDimmed Red: ");
Serial.print(rd); //get red component
Serial.print("\tGreen: ");
Serial.print(gd); //get green
Serial.print("\tBlue: ");
Serial.println(bd); //get blue
fill_solid( leds, NUM_LEDS, CRGB(rd,gd,bd));
FastLED.show();
}
Tested with ESP32 and ESP-8266, with UPnP disabled for more than 20 times, none of them needs it to be enabled for discovery.
I really suggest removing "Espalexa might need to have UPnP enabled for discovery to work" in readme.md as UPnP adds more risk to security.
Hi, I'm not sure if it's me or something on the ESPAlexa code, so I'll ask, I've been pinging the ESP while sending commands and if I send commands through my phone (my own app) or Windows Chrome, sometimes I get timeouts... like if it's getting stuck and stop answering for a second and then IP goes up again and the command works.
Has anyone see this behavior ? Usually is when you send MORE than one request too quickly.
Hi,
if you dimm to the smallest value (1%) via alexa APP the Brightness switches to 5.
But after few seconds the value in the APP jumps to 2%.
Is it possible that the smallest Brightness have to be more less, for example 3?
Hi,
i spent a lot of time in converting white/warmwhite color modes to RGB.
And in my opinion it looks more like the expectation if i see the APP. No, i haven't an original HUE Product π
Here's my code:
long miredtokelvin(long mired) {
long kelvin = round(1000000 / mired);
return kelvin;
}
long kelvintomired(long kelvin) {
long mired = round(1000000 / kelvin);
return mired;
}
int *CTtoRGB(int ct, int v, int & R, int & G, int & B) {
// https://github.com/twerff/CTtoRGB
// https://forum.arduino.cc/index.php?topic=103681.msg778719#msg778719
// http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
float r, g, b;
int k = miredtokelvin(ct);
int ktemp = k / 100;
if ( DEBUG == true ) { Serial.print("ct: "); Serial.print(ct); Serial.print(", Kelvin: "); Serial.print(k); Serial.print(", v: "); Serial.println(v); }
if ( ktemp <= 66 ) {
r = 255;
g = ct;
g = 99.4708025861 * log(g) - 161.1195681661;
if ( ktemp <= 19) {
b = 0;
} else {
b = ktemp - 10;
b = 138.5177312231 * log(b) - 305.0447927307;
}
} else {
r = ktemp - 60;
r = 329.698727446 * pow(r, -0.1332047592);
g = ktemp - 60;
g = 288.1221695283 * pow(g, -0.0755148492 );
b = 255;
}
if ( r < 0 ) r = 0; if ( r > 255 ) r = 255;
if ( g < 0 ) g = 0; if ( g > 255 ) g = 255;
if ( b < 0 ) b = 0; if ( b > 255 ) b = 255;
R = round( r / 255 * v );
G = round( g / 255 * v );
B = round( b / 255 * v );
}
Later you need:
('ct' is the white level. alexa gives it in range of 199(cold)-383(warmest))
int R, G, B;
CTtoRGB(ct, brightness, R, G, B);
In the read.me it mentions.
"It allows you to set a ranged value (e.g. Brightness, Temperature) additionally to standard on/off control. For example, you can say "Alexa, turn the light to 75% / 21 degrees"".
Can you please show an example of how this is done
Hello,
thank you so much for this library!! I tried a few others but this is the only one that worked for me!
I have applied the fix you suggested in this issue and the system is now working with esp8266 core version 2.4.2.
However I am experiencing an issue. I have got 3x esp8266 boards (adafruit Huzzah) each with 2 to 4 emulated devices loaded with your library. Four of these devices are programmed to do exactly what @st2000 has suggested to control an RGB strip (I also put there a white option to control all colours at once). The esp8266 then sends some strings to an arduino uno board for PWM control. Never mind the convoluted system here.
Basically the issue I have is that Alexa says cannot apply the SET command to these devices. ON and OFF commands work though.
What's weird is that all the other devices in the network, connected only to relays, accept the SET command! Alexa says 'ok' and turns the device on (I use a digitalWrite command to control a relay, so no dimming here, but the voice command seems to work).
But for the 'red' 'green' blue' and 'white' devices Alexa asks 'sorry what device?' and then says 'I don't know how to set red (or green,blue,white) to that setting'. However, I can control the brightness with the Alexa app!! But not from a voice command.
What's even more weird, is that once or twice, the SET command has worked for the 'white' device. Then it stopped working.
Any ideas?
Code here
/*
* This is a basic example on how to use Espalexa and its device declaration methods.
*/
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <Espalexa.h>
// prototypes
boolean connectWifi();
//callback functions
void firstLightChanged(uint8_t brightness);
void secondLightChanged(uint8_t brightness);
void thirdLightChanged(uint8_t brightness);
void fourthLightChanged(uint8_t brightness);
// Change this!!
const char* ssid = "SSSuperWiFi";
const char* password = "M1ch3l3p4n3gr0ss1!";
boolean wifiConnected = false;
const int cabinetPin = 12;
const int planterPin = 13;
const int ledPin = 0;
Espalexa espalexa;
EspalexaDevice* device3; //this is optional
void setup()
{
Serial.begin(115200);
// Initialise wifi connection
pinMode(cabinetPin, OUTPUT);
pinMode(planterPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(cabinetPin, LOW);
digitalWrite(planterPin, LOW);
digitalWrite(ledPin, LOW);
wifiConnected = connectWifi();
if(wifiConnected){
// Define your devices here.
espalexa.addDevice("red", firstLightChanged); //simplest definition, default state off
espalexa.addDevice("green", secondLightChanged); //third parameter is beginning state (here fully on)
espalexa.addDevice("blue", thirdLightChanged); //third parameter is beginning state (here fully on)
espalexa.addDevice("white", fourthLightChanged); //third parameter is beginning state (here fully on)
espalexa.begin();
} else
{
while (1) {
Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
delay(2500);
}
}
}
void loop()
{
espalexa.loop();
delay(1);
}
//our callback functions
//Cabinet right
void firstLightChanged(uint8_t brightness) {
//Serial.print("Cabinet changed to ");
if (brightness) {
//Serial.print("ON, brightness ");
//Serial.println(brightness);
String s = "s";
s += ",";
s += "RED";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
else {
String s = "s";
s += ",";
s += "RED";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
}
//grower right
void secondLightChanged(uint8_t brightness) {
//Serial.print("planterPin changed to ");
if (brightness) {
String s = "s";
s += ",";
s += "GREEN";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
else {
String s = "s";
s += ",";
s += "GREEN";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
}
//blue
void thirdLightChanged(uint8_t brightness) {
//Serial.print("planterPin changed to ");
if (brightness) {
String s = "s";
s += ",";
s += "BLUE";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
else {
String s = "s";
s += ",";
s += "BLUE";
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
}
//blue
void fourthLightChanged(uint8_t brightness) {
//Serial.print("planterPin changed to ");
if (brightness) {
String s = "s";
s += ",";
s += "WHITE";
s += ",";
s += String(brightness);
s += ",";
s += String(brightness);
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
else {
String s = "s";
s += ",";
s += "WHITE";
s += ",";
s += String(brightness);
s += ",";
s += String(brightness);
s += ",";
s += String(brightness);
s += "\n";
Serial.print(s);
}
}
// connect to wifi β returns true if successful or false if not
boolean connectWifi(){
boolean state = true;
int i = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false; break;
}
i++;
}
Serial.println("");
if (state){
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("Connection failed.");
}
return state;
}
Hi, I'm trying to add my serial prints to check my code but the library itself prints a LOT of info and I'm not sure how to set the debug OFF in the library. Can you help me ?
By the way, is it normal that there's SO MANY of this messages ? (I mean, like 2 Got UDP! messages every 1 or 2 seconds)
And thanks, the library seems AMAZING ! I was using Fauxmo but wanted some with brightness to use with my devices for so long... Keep this one alive ! You rock :)
Got UDP! NOTIFY * HTTP/1.1 HOST:239.255.255.250:1900 CACHE-CONTROL:max-age=16 LOCATION:http://192.168.0.254:8200/rootDesc.xml SERVER: 3.14.77 DLNADOC/1.50 UPnP/1.0 MiniDLNA/1.1.5 NT:urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1 USN:uuid:4d696e69-44 Got UDP! NOTIFY * HTTP/1.1 HOST: 239.255.255.250:1900 CACHE-CONTROL: max-age=100 LOCATION: http://192.168.0.240:80/description.xml SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/1.24.0 NTS: ssdp:alive hue-bridgeid: 001788FFFE4AAC68 NT: urn:schemas-upnp-org:device:b Got UDP! NOTIFY * HTTP/1.1 HOST: 239.255.255.250:1900 CACHE-CONTROL: max-age=100 LOCATION: http://192.168.0.240:80/description.xml SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/1.24.0 NTS: ssdp:alive hue-bridgeid: 001788FFFE4AAC68 NT: urn:schemas-upnp-org:device:b Got UDP!
Hi, I'm trying to build an android application to be able to turn on/off devices and also set specific "brightness" to each device, and my question is:
What JSON format is ESPAlexa expecting ? I tried with the HUE format but I'm not sure how to specific each device. For example I tried posting to:
http://MY_ESP_IP:80/api/2WLEDHardQrI3WHYTHoMcXHgEspsM8ZZRpSKtBQr/lights/1/state
This JSON: {"on":false, "bri":0}
Usually that code, using my Hue App ID instead of yours of course, is enough, but in this case, I get a success response but no light is activated or changed. Ideas of my mistake ?
Thanks a lot.
I am getting definition conflict when I useEspAlexa with EspAsyncWebserver
In file included from ~.platformio\lib\Espalexa_ID5525\src/Espalexa.h:8:0,
from src\src.cpp:23:
~.platformio\lib\Espalexa_ID5525\src/dependencies/webserver/WebServer.h:36:85: error: redeclaration of 'HTTP_OPTIONS'
enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS };
First - a big shoutout to your work! Your code is the only one, that worked as expected. Thanks alot!
So, now the feature request: Is there a way to implement RGB-Strip support? At the moment i see only a possible work-around: add devices with names red, blue, yellow and so on and hardcode the color in each callback-function.
But it would be much easier if the simulated device could set as an RGB-Strip instead of a Light with just the brightness-mode. Only say: alexa, set the color of "devicename" to red.... for example.
Here are so many smart heads - do someone have an idea to realize that?
Hallo Aircoookie,
I added the WifiManager because i love it π
BUT i don't know if it will work with ESP32 π’
Greetings (viele GrΓΌΓe)
Christian...
VoilΓ :
/*
This is a basic example on how to use Espalexa with RGB color devices.
*/
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <Espalexa.h>
//callback function prototype
void colorLightChanged(uint8_t brightness, uint32_t rgb);
Espalexa espalexa;
void setup()
{
Serial.begin(115200);
WiFiManager wifiManager;
if (!wifiManager.autoConnect("Espalexa")) {
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
} else {
Serial.println("connected to WIFI..");
espalexa_addDevices();
espalexa.begin();
}
Serial.println("Now it's time to ask alexa to discover devices...");
}
void loop()
{
espalexa.loop();
delay(1);
}
void espalexa_addDevices() { // add Devices you want
espalexa.addDevice("Light", colorLightChanged);
}
//the color device callback function has two parameters
void colorLightChanged(uint8_t brightness, uint32_t rgb) {
//do what you need to do here, for example control RGB LED strip
Serial.print("Brightness: ");
Serial.print(brightness);
Serial.print(", Red: ");
Serial.print((rgb >> 16) & 0xFF); //get red component
Serial.print(", Green: ");
Serial.print((rgb >> 8) & 0xFF); //get green
Serial.print(", Blue: ");
Serial.println(rgb & 0xFF); //get blue
}
This library is so far the best implementation for ESP devices. The on/off/dim/colour controls with Alexa app is an amazing feature and are working very well.
However, I find apps control feature is not fully implemented and does not fully work with other apps:
Philips Hue
Search button can't find any bridge with an error message: No new Hue Bridge found
Using help button to enter IP address will get the same message. I think a reply is not implemented.
Hue Hello
It can't search Hue bridge but is able to search light devices. From this apps, it seems some data of bridge may not be available. These including Mac address, Model, IP Address, Software version and Timezone. And after creating a group with some light devices, the group cannot be saved.
This apps supports only one bridge with many smart devices. But this library creates one bridge for one ESP modules. Will this approach causes future compatibility problem? But Philips Hue seems to accept more than one bridge. This is what I am confused.
Using a previously working sketch it was rebuilt using the latest Espalexa 2.3.3 and the release 2.5.0 for the ESP8266. The return value is always 255 for On or Off much like what occurred with 2.4.2 without the webserver file hack. My understanding was that issue which is related to the Alexa itself was corrected in the 2.5.0 but yet the behavior of the sketch has reverted back to how it worked without the 8266 library hack.
Have you seen this behavior or is there something else I need to do with the 2.3.3 and the 2.5.0?
Thanks, your support is appreciated.
I went crazy for 2 days because I was not able to get a command in my code.
What happened is the following:
I converted a previous sketch to use espalexa. So used the same device name used before.
Device was discovered, command sent but nothing received by my program.
Delete device and try again, same . Power off esp32 , delete devices and run discover again and the device name appeared, send a command and get device malfunction message (it waS POWERED OFF).
I used the Espalexa sample program and it works. So today a changed the device name to a new one and it was discovered( after a couple of attempts) and it works.
So I'm guessing that I was using the device name with Sinric in the past and it is still associated somehow to me.
possible?
Hi,
if i try to define Espalexa in fhem, it ran into timeout with the message HUEBridge_HTTP_Request http://<Espalexa IP>/api/<serial>/config: Select timeout/error: Interrupted system call
Do you think it's possible to fill this page with correct data?
Greetings,
Christian...
Every example I searched for ESP8266 / ESP32 and alexa integration found out to be just a faking of some existing device protocol like Philips Hue or WemO
You have done a great work as this is only code that work seamlessly with my devices, and my Alexa Echo dot discovered all added device immediately.
But what i'm searching for is to add native discovery to my device. Like Alexa should be able to understand my device name and company/manufacturer name after discovery, as i want to use for production purpose. I need similar SSDP like functionality for my devices.
I tried searching for it but could find a proper documentation.
Do you have any idea about how it can be done?
hello, I would like to know if it is possible to send a feedbak to Alexa on the actual status of the command sent. I'll explain. I ask Alexa to turn on the light and it is ESP that sends alexa a feedbak if the light has been switched on or not. I do not know if I'm clear enough, I write very badly in English ...Grazie
Using the basic example built with 8266 2.3.0 the returned value for the brightness is one count higher then the bri parameter in the library.
ON returns 255 and OFF returns 0 but setting to 100% from Alexa returns a value of zero because of the uint8_t declaration rollover but the bri parameter is 255 as it should be.
Setting to 0% returns a value of one with the bri parameter at zero.
Is this by design?
Thanks.
Dear friends,
I would kindly ask for help. The espalexa is a great module. Thanks for that. Already implement several times. But nowadays I got this issue
Void setup -> register alexa devices using
int i = 6
espalexa.addDevice("switch one", switch(i));
void switch(int switch_nr, uint8_t value); switch_nr I need to know which relay to use, and value to get 0-255 to understand if "On" or "Off" should be applied.
I'm unable to create a void for each relay 1-24 and the call it espalexa.addDevice("switch one", switch_one()); espalexa.addDevice("switch two", switch_two());.....
Small note: not each of relay1-24 is enabled for alexa usage so for each I check if yes or no
Is there a way how to do it.
Thanks for your help
Lukas
When using latest Alexa App to control (on, off, dimming) ESP32 light devices, the light devices will become "Device malfunction" or "Device is unresponsive" randomly. And killing the App and restart it 1 or 2 times, most devices will show the error message. And http://[device-ip]/espalexa
can't be connected. Reseting the ESP32 module can make the devices work again.
Image of Alexa App with Error Messages
The Alexa app version:
Client Version: 1.24.204839.0
App Version: 2.2.250163.0
OS: Android 8
Using ESP-8266, all control functions work. Never find a problem so far.
can I use this library with FreeRTOS to integrate Alexa support in ESP-HomeKit devices? How?
Hi Aircookie,
nice work - your script works like a charm, right out of the box and stable with 5+ devices. I tried a few things with the IRremote Library for ESP8266 (https://github.com/markszabo/IRremoteESP8266) but could not get it to work. It seems that the pins are not controlled properly. All examples from the IR library work without problems (tested on Wemos D1 mini) and problems only occur in conjunction with the Espalexa script. Do you have any ideas why that is the case and how to fix it?
Thanks for the good work.
bchwtz
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.