Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*Feature Request* - RGB-Strip simulation instead of "just" a light #18

Closed
s3nfinator opened this issue Sep 23, 2018 · 3 comments
Closed

Comments

@s3nfinator
Copy link

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?

led-strip

@Aircoookie
Copy link
Owner

Hi! Thank you, I'm glad that you like my library :)

Amazon essentially uses two different ways to communicate to different devices. Most use cloud servers operated by the vendor of the smart home device. You know this is the case when you have to install an Alexa "skill" and log in with your smart home device account.
Espalexa uses the local Philips hue API. Although the API spec obviously supports changing colors, Amazon has only implemented the On/Off and Brightness parts for Alexa, leaving color support for the cloud solution exclusively.
So sadly, I can't add color support at this time. I'd already have implemented it if it was possible. Sorry!

Trotzdem noch einen schönen Sonntag :)

@st2000
Copy link

st2000 commented Oct 3, 2018

I don't see the problem with treating each color (red, green & blue (& for some strips white)) as a different device. @Aircoookie is allowing up to 20 devices. You could then say "set blue to 20%", "set red to 80%" & "set green to 80%" to get yellow. Or, you could program Alexa to do a "macro" (I forget what this is really called) and just say "Alexa, I want it yellow" and have Alexa execute these 3 steps to turn your strip yellow. And, yes, for every color you would need to enter a new phrase and set of commands.

@michelepanegrossi
Copy link

michelepanegrossi commented Dec 5, 2018

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 esp devices (adafruit Huzzah) each with 2 to 4 emulated devices loaded with your code. 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 colors at once). The esp 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.

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, 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 = "****************";
const char* password = "*************";

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants