try homeassistant discovery
This commit is contained in:
parent
570321be6c
commit
c83210c4a6
49
src/main.cpp
49
src/main.cpp
|
|
@ -332,6 +332,55 @@ void mqttRefresh()
|
|||
mqtt.subscribe(FLIPDOT_SWITCH_TOPIC);
|
||||
mqtt.subscribe(FLIPDOT_TEXT_TOPIC);
|
||||
mqtt.publish(FLIPDOT_AVAILABILITY_TOPIC, "available");
|
||||
|
||||
auto mac = WiFi.macAddress();
|
||||
mac.replace(":","_");
|
||||
|
||||
JsonDocument doc;
|
||||
JsonObject device = doc["dev"].to<JsonObject>();
|
||||
device["ids"] = mac;
|
||||
device["name"] = "FlipDotDisplay";
|
||||
device["mf"] = "-mf-";
|
||||
device["mdl"] = "-mdl-";
|
||||
device["sw"] = "-sw-";
|
||||
device["sn"] = "-sn-";
|
||||
device["hw"] = "-hw-";
|
||||
|
||||
JsonObject origin = doc["o"].to<JsonObject>();
|
||||
origin["name"] = "Hobbyhimmel";
|
||||
origin["sw"] = "-sw-";
|
||||
origin["url"] = "https://hobbyhimmel.de";
|
||||
|
||||
JsonObject components = doc["cmps"].to<JsonObject>();
|
||||
JsonObject sw = doc["FlipDotDisplaySwitch"].to<JsonObject>();
|
||||
sw["unique_id"] = mac + "FlipDotDisplaySwitch";
|
||||
sw["p"] = "switch";
|
||||
sw["command_topic"] = FLIPDOT_SWITCH_TOPIC;
|
||||
sw["state_topic"] = FLIPDOT_SWITCH_TOPIC"/state";
|
||||
sw["payload_on"] = "open";
|
||||
sw["payload_off"] = "close";
|
||||
sw["qos"] = 0;
|
||||
sw["retain"] = false;
|
||||
|
||||
JsonObject txt = doc["FlipDotDisplayText"].to<JsonObject>();
|
||||
sw["unique_id"] = mac + "FlipDotDisplayText";
|
||||
sw["p"] = "text";
|
||||
sw["command_topic"] = FLIPDOT_TEXT_TOPIC;
|
||||
sw["state_topic"] = FLIPDOT_TEXT_TOPIC"/state";
|
||||
sw["qos"] = 0;
|
||||
sw["retain"] = false;
|
||||
|
||||
doc["availability_topic "] = FLIPDOT_AVAILABILITY_TOPIC;
|
||||
|
||||
String jsonString;
|
||||
serializeJson(doc, jsonString);
|
||||
|
||||
String discoveryTopic = "homeassistant/device/";
|
||||
discoveryTopic += mac + "/config";
|
||||
|
||||
mqtt.publish(discoveryTopic.c_str(), jsonString.c_str());
|
||||
Serial.print("Homeassistant Discovery was published: ");
|
||||
Serial.println(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user