Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. /*
  2. ALEXA MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if ALEXA_SUPPORT
  6. #include <fauxmoESP.h>
  7. fauxmoESP alexa;
  8. // -----------------------------------------------------------------------------
  9. // ALEXA
  10. // -----------------------------------------------------------------------------
  11. void alexaConfigure() {
  12. alexa.enable(getSetting("alexaEnabled", ALEXA_ENABLED).toInt() == 1);
  13. }
  14. void alexaSetup() {
  15. // Backwards compatibility
  16. moveSetting("fauxmoEnabled", "alexaEnabled");
  17. alexaConfigure();
  18. unsigned int relays = relayCount();
  19. String hostname = getSetting("hostname");
  20. if (relays == 1) {
  21. alexa.addDevice(hostname.c_str());
  22. } else {
  23. for (unsigned int i=0; i<relays; i++) {
  24. alexa.addDevice((hostname + "_" + i).c_str());
  25. }
  26. }
  27. alexa.onMessage([relays](unsigned char device_id, const char * name, bool state) {
  28. DEBUG_MSG_P(PSTR("[ALEXA] %s state: %s\n"), name, state ? "ON" : "OFF");
  29. relayStatus(device_id, state);
  30. });
  31. }
  32. void alexaLoop() {
  33. alexa.handle();
  34. }
  35. #endif