|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
12 #if SUPPORT_HA_DISCOVERY
85 size_t HASwitch::getDiscoveryJson (
char* buffer,
size_t buflen,
const char* nodeName,
const char* networkName, DynamicJsonDocument* inputJSON) {
87 DynamicJsonDocument outputJSON (1024);
91 if (!nodeName || !networkName || !inputJSON ) {
92 DEBUG_WARN (
"Whrong parameters");
97 outputJSON[
"name"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
99 outputJSON[
"name"] = nodeName;
102 outputJSON[
"unique_id"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
104 outputJSON[
"unique_id"] = nodeName;
106 outputJSON[
"command_topic"] = String (networkName) +
"/" + String (nodeName) +
"/set/data";
113 outputJSON[
"state_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
115 outputJSON[
"state_on"] = (*inputJSON)[
ha_state_on];
121 outputJSON[
"value_template"] = String (
"{{value_json.") + (*inputJSON)[
ha_value_key].as<String> () + String (
"}}");
124 outputJSON[
"json_attributes_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
125 outputJSON[
"json_attributes_template"] =
"{{value_json | tojson}}";
128 size_t jsonLen = measureJson (outputJSON);
130 if (jsonLen > buflen) {
131 DEBUG_WARN (
"Too small buffer. Required %u Has %u", jsonLen, buflen);
136 serializeJson (outputJSON, buffer, 1024);
141 #endif // SUPPORT_HA_DISCOVERY
Home Assistant switch integration.
constexpr auto ha_state_on
void setStateOn(const char *payload)
The payload that represents the on state. Used when value that represents on state in the state_topic...
constexpr auto ha_allow_attrib
constexpr auto ha_name_sufix
constexpr auto ha_payload_off
void setStateOff(const char *payload)
The payload that represents the off state. Used when value that represents off state in the state_top...
void setPayloadOff(const char *payload)
The payload that represents off state. If specified, will be used for both comparing to the value in ...
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 Switch template.
constexpr auto ha_state_off
constexpr auto ha_payload_on
void setPayloadOn(const char *payload)
The payload that represents on state. If specified, will be used for both comparing to the value in t...
void setValueField(const char *payload)
Defines a json key to extract device’s state from the state_topic. To determine the switches’s state ...
constexpr auto ha_value_key