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.

44 lines
1.0 KiB

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