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.

60 lines
1.7 KiB

  1. /*
  2. HOME ASSISTANT MODULE
  3. Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if HOMEASSISTANT_SUPPORT
  6. void haSend() {
  7. DEBUG_MSG_P(PSTR("[HA] Sending autodiscovery MQTT message\n"));
  8. String component = String("light");
  9. DynamicJsonBuffer jsonBuffer;
  10. JsonObject& root = jsonBuffer.createObject();
  11. root["name"] = getSetting("hostname");
  12. root["platform"] = "mqtt";
  13. if (relayCount()) {
  14. root["state_topic"] = getTopic(MQTT_TOPIC_RELAY, 0, false);
  15. root["command_topic"] = getTopic(MQTT_TOPIC_RELAY, 0, true);
  16. }
  17. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  18. if (lightHasColor()) {
  19. root["brightness"] = 1;
  20. root["brightness_state_topic"] = getTopic(MQTT_TOPIC_BRIGHTNESS, false);
  21. root["brightness_command_topic"] = getTopic(MQTT_TOPIC_BRIGHTNESS, true);
  22. root["rgb"] = 1;
  23. root["rgb_state_topic"] = getTopic(MQTT_TOPIC_COLOR, false);
  24. root["rgb_command_topic"] = getTopic(MQTT_TOPIC_COLOR, true);
  25. root["color_temp"] = 1;
  26. root["color_temp_command_topic"] = getTopic(MQTT_TOPIC_MIRED, true);
  27. }
  28. if (lightChannels() > 3) {
  29. root["white_value"] = 1;
  30. root["white_value_state_topic"] = getTopic(MQTT_TOPIC_CHANNEL, 3, false);
  31. root["white_value_command_topic"] = getTopic(MQTT_TOPIC_CHANNEL, 3, true);
  32. }
  33. #endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  34. String output;
  35. root.printTo(output);
  36. String topic = getSetting("haPrefix", HOMEASSISTANT_PREFIX)
  37. + String("/") + component + "/" + getSetting("hostname");
  38. mqttSendRaw(topic.c_str(), output.c_str());
  39. }
  40. #endif // HOMEASSISTANT_SUPPORT