|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
11 #if SUPPORT_HA_DISCOVERY
80 DynamicJsonDocument outputJSON (1024);
84 if (!nodeName || !networkName || !inputJSON ) {
85 DEBUG_WARN (
"Whrong parameters");
90 outputJSON[
"name"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
92 outputJSON[
"name"] = nodeName;
95 outputJSON[
"unique_id"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
97 outputJSON[
"unique_id"] = nodeName;
99 outputJSON[
"state_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
111 templ.replace (
"***", nodeName);
112 outputJSON[
"value_template"].set<String> (templ);
114 outputJSON[
"value_template"] = String (
"{{value_json.") + (*inputJSON)[
ha_value_key].as<String> () + String (
"}}");
116 outputJSON[
"value_template"] =
"{{value_json.value}}";
119 outputJSON[
"expire_after"] = (*inputJSON)[
ha_expiration].as<
int> ();
122 outputJSON[
"off_delay"] = (*inputJSON)[
ha_off_delay].as<
int> ();
125 outputJSON[
"json_attributes_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
126 outputJSON[
"json_attributes_template"] =
"{{value_json | tojson}}";
129 size_t jsonLen = measureJson (outputJSON);
131 if (jsonLen > buflen) {
132 DEBUG_WARN (
"Too small buffer. Required %u Has %u", jsonLen, buflen);
137 serializeJson (outputJSON, buffer, 1024);
143 switch (sensorClass) {
147 return "battery_charging";
151 return "connectivity";
155 return "garage_door";
constexpr auto ha_device_class
static String deviceClassStr(haBinarySensorClass_t sensorClass)
Gets binary sensor class name from haBinarySensorClass_t https://www.home-assistant....
void setValueField(const char *payload)
Defines a template that returns a string to be compared to payload_on/payload_off or an empty string,...
void setValueTemplate(const char *payload)
Defines a template that defines binary sensor value. When setting this you should not call setValueFi...
constexpr auto ha_allow_attrib
constexpr auto ha_name_sufix
constexpr auto ha_payload_off
constexpr auto ha_expiration
static size_t getDiscoveryJson(char *buffer, size_t buflen, const char *nodeName, const char *networkName, DynamicJsonDocument *inputJSON)
Allows Gateway to get Home Assistant discovery message using Binary Sensor template.
constexpr auto ha_value_template
void setPayloadOff(const char *payload)
Defines the string that represents the off state. It will be compared to the message in the state_top...
void setPayloadOn(const char *payload)
Defines the string that represents the on state. It will be compared to the message in the state_topi...
constexpr auto ha_payload_on
Home Assistant binary sensor integration.
void setOffDelay(uint payload)
For sensors that only send on state updates (like PIRs), this sets a delay in seconds after which the...
void setDeviceClass(haBinarySensorClass_t devClass)
Define binary sensor class as haBinarySensorClass_t
constexpr auto ha_off_delay
constexpr auto ha_value_key