|
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
65 size_t HASensor::getDiscoveryJson (
char* buffer,
size_t buflen,
const char* nodeName,
const char* networkName, DynamicJsonDocument* inputJSON) {
67 DynamicJsonDocument outputJSON (1300);
71 if (!nodeName || !networkName || !inputJSON ) {
72 DEBUG_WARN (
"Whrong parameters");
77 outputJSON[
"name"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
79 outputJSON[
"name"] = nodeName;
82 outputJSON[
"unique_id"] = String (nodeName) +
"_" + (*inputJSON)[
ha_name_sufix].as<String> ();
84 outputJSON[
"unique_id"] = nodeName;
90 outputJSON[
"expire_after"] = (*inputJSON)[
ha_expiration].as<
int>();
92 outputJSON[
"state_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
98 templ.replace (
"***", nodeName);
99 outputJSON[
"value_template"].set<String> (templ);
101 outputJSON[
"value_template"] = String (
"{{value_json.") + (*inputJSON)[
ha_value_key].as<String> () + String (
"}}");
103 outputJSON[
"value_template"] =
"{{value_json.value}}";
106 outputJSON[
"json_attributes_topic"] = String (networkName) +
"/" + String (nodeName) +
"/data";
107 outputJSON[
"json_attributes_template"] =
"{{value_json | tojson}}";
110 size_t jsonLen = measureJson (outputJSON);
112 if (jsonLen > buflen) {
113 DEBUG_WARN (
"Too small buffer. Required %u Has %u", jsonLen, buflen);
118 serializeJson (outputJSON, buffer, 1024);
124 switch (sensorClass) {
134 return "illuminance";
136 return "signal_strength";
138 return "temperature";
142 return "power_factor";
154 #endif // SUPPORT_HA_DISCOVERY
constexpr auto ha_device_class
void setValueField(const char *payload)
Defines a json key that defines sensor value. When setting this, setValueTemplate () should not be ca...
void setDeviceClass(haSensorClass_t devClass)
Define sensor class as haSensorClass_t https://www.home-assistant.io/integrations/sensor....
static String deviceClassStr(haSensorClass_t sensorClass)
Gets sensor class name from haSensorClass_t https://www.home-assistant.io/integrations/sensor....
constexpr auto ha_allow_attrib
constexpr auto ha_name_sufix
Home Assistant sensor integration.
constexpr auto ha_expiration
constexpr auto ha_value_template
void setUnitOfMeasurement(const char *payload)
Set unit of measure https://www.home-assistant.io/integrations/sensor.mqtt/#unit_of_measurement.
constexpr auto ha_unit_of_measurement
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 Sensor template.
void setExpireTime(uint payload)
Defines the number of seconds after the sensor’s state expires, if it’s not updated....
void setValueTemplate(const char *payload)
Defines a template that defines sensor value. When setting this you should not call setValueField () ...
constexpr auto ha_value_key