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.

46 lines
1.1 KiB

  1. /*
  2. ESPurna
  3. DHT MODULE
  4. Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
  5. */
  6. #if ENABLE_FAUXMO
  7. #include <fauxmoESP.h>
  8. fauxmoESP fauxmo;
  9. // -----------------------------------------------------------------------------
  10. // FAUXMO
  11. // -----------------------------------------------------------------------------
  12. void fauxmoConfigure() {
  13. fauxmo.enable(getSetting("fauxmoEnabled", FAUXMO_ENABLED).toInt() == 1);
  14. }
  15. void fauxmoSetup() {
  16. fauxmoConfigure();
  17. unsigned int relays = relayCount();
  18. String hostname = getSetting("hostname", HOSTNAME);
  19. if (relays == 1) {
  20. fauxmo.addDevice(hostname.c_str());
  21. } else {
  22. for (unsigned int i=0; i<relays; i++) {
  23. fauxmo.addDevice((hostname + "_" + i).c_str());
  24. }
  25. }
  26. fauxmo.onMessage([relays](const char * name, bool state) {
  27. DEBUG_MSG("[FAUXMO] %s state: %s\n", name, state ? "ON" : "OFF");
  28. unsigned int id = 0;
  29. if (relays > 1) {
  30. id = name[strlen(name)-1] - '0';
  31. if (id >= relays) id = 0;
  32. }
  33. relayStatus(id, state);
  34. });
  35. }
  36. #endif