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.

45 lines
1.0 KiB

  1. /*
  2. ESPurna
  3. DHT MODULE
  4. Copyright (C) 2016-2017 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](unsigned char device_id, const char * name, bool state) {
  27. DEBUG_MSG("[FAUXMO] %s state: %s\n", name, state ? "ON" : "OFF");
  28. relayStatus(device_id, state);
  29. });
  30. }
  31. void fauxmoLoop() {
  32. fauxmo.handle();
  33. }
  34. #endif