vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
383 stars 69 forks source link

Fauxmo ESP8266 Not recognized as a Bulb,etc. #112

Closed pvint closed 3 years ago

pvint commented 4 years ago

Original report by Cole Rabe (Bitbucket: [Cole Rabe](https://bitbucket.org/Cole Rabe), ).


When I use the example sketches, the first thing that I have noticed is that I am not able to add more than 3 devices and then have the amazon echo discover them. Both example sketchs for me have this issue. The bigger issue for me is that when I do get the amazon echo to discover my devices (again, only 3), they do not show up as lights. Do I need any special smart home skill to make this work, or is there anything I need to modify code-wise to allow the echo to detect the device type? While my code is not the example sketch, it should theoretically work the same. Let me know however if there is any changes in my code that would need to be made to solve my issue!

Thanks!

Board: ESP8266

Echo Model: Amazon Echo Dot Version 3

Library Version: v3.1.1

Code:

#include <Arduino.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFi.h>
#include <fauxmoESP.h>
#define WIFI_SSID "Wireless" // Please Enter you Wifi name here
#define WIFI_PASS "7817293793" // Enter password here
#define SERIAL_BAUDRATE     115200
fauxmoESP fauxmo;
void setup() {
    WiFi.hostname("MyESP8266");
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println("~~~Basement TV LED Driver~~~");
     pinMode(D0, OUTPUT); 
     pinMode(D1, OUTPUT);
     pinMode(D2, OUTPUT); 
    Serial.println("Connecting to Network:");
    if (connectWifi()) {
    // Setup fauxmo
     fauxmo.setPort(80);  
     fauxmo.enable(true);
     fauxmo.addDevice("Basement TV LED Red");
     fauxmo.addDevice("Basement TV LED Green");
     fauxmo.addDevice("Basement TV LED Blue");
  }
   fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
        Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);

        if (strcmp(device_name, "Basement TV LED Red")==0) {
           if(state){
            digitalWrite(D0, HIGH);
            }
            else {
            digitalWrite(D0, LOW);
              }
}
       if (strcmp(device_name, "Basement LED Green")==0) {
           if(state){
            digitalWrite(D1, HIGH);
              }
            else {
            digitalWrite(D1, LOW);
              }
}
      if (strcmp(device_name, "Basement LED Blue")==0) {
           if(state){
            digitalWrite(D2, HIGH);
            }
            else {
            digitalWrite(D2, LOW);
              }
}
}
);
}
void loop() {
    fauxmo.handle();
}
boolean connectWifi() {
    WiFi.mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(100);
        }
    Serial.println(".......");
    Serial.println("WiFi Connected....IP Address: ");
    Serial.print(WiFi.localIP());
  return true;
}

pvint commented 3 years ago

I've been finding recently that when I add the devices, alexa adds them fine, but they show up in the app as a generic device as opposed to a light. It still functions as a light when I give voice commands, however.

Also, if I create a group in the Alexa app, and add device(s) to it, I can turn it off and on through the app (no dimming though). I'll be looking into this more. (Using Echo Dot Gen3).

for only being able to ad three devices - can you post the serial output? (Edit: also add #define DEBUG_FAUXMO Serial to your code for more info)

Thanks Paul

StoeSeppl commented 3 years ago

I've been confronted with the same problem. I recognized, that the alexa app is showing the fauxmo devices as type:"other" ("sonstige" in german, don't know what the exact naming in the english version is). So I started looking at FAUXMO_DEVICE_JSON_TEMPLATE[], where the type is declaired. I don't have any phillips bulbs but I recognized LTC007 is very old. Lacking of an example from Phillips I researched what type my ikea bulbs are exposing and exchanged the JSON to the following: PROGMEM const char FAUXMO_DEVICE_JSON_TEMPLATE[] = "{" "\"type\":\"Dimmable light\"," "\"name\":\"%s\"," "\"uniqueid\":\"%s%06d\"," "\"modelid\":\"TRADFRI_bulb_E14_W_op_ch_400lm\"," "\"state\":{" "\"on\":%s,\"bri\":%d,\"xy\":[0,0],\"reachable\": true" "}," "\"capabilities\":{" "\"certified\":false," "\"streaming\":{\"renderer\":true,\"proxy\":false}" "}," "\"swversion\":\"5.105.0.21169\"" "}";

From now on new devices are discovered as a light by the app and I can use the Alexa app for dimming and switching manually. I can even replace the modelid with "fauxmo" and the discovery works as expected. The type property seems to be the counting one.

pvint commented 3 years ago

Awesome! Thanks @StoeSeppl !

I had played around with the modelid some with no success, but simply changing the type made it work!

A bit of a further test revealed that simply fixing the case of the type was the real key (instead of Extended Color Light change it to Extended color light).

I committed the change to master, but I'm still working on it. This gave me the one step I needed to get colours working.

pvint commented 3 years ago

Fixed in 0812901f0a564080a94241c6b9cc82e160de2f20