mirror of https://github.com/arendst/Tasmota.git
Update xdrv_12_home_assistant.ino
This commit is contained in:
parent
70ea4bedfa
commit
74081073ba
|
@ -91,6 +91,10 @@ const char HASS_DISCOVER_SENSOR_TEMP[] PROGMEM =
|
||||||
"\"val_tpl\":\"{{value_json['%s'].Temperature}}\"," // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Temperature }}
|
"\"val_tpl\":\"{{value_json['%s'].Temperature}}\"," // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Temperature }}
|
||||||
"\"dev_cla\":\"temperature\""; // temperature
|
"\"dev_cla\":\"temperature\""; // temperature
|
||||||
|
|
||||||
|
const char HASS_DISCOVER_DS18X20_MULTI[] PROGMEM =
|
||||||
|
",\"json_attributes_topic\":\"%s\","
|
||||||
|
"\"json_attributes_template\":\"{{{'Id':value_json['%s'].Id}|tojson}}\""; // Add DS18X20 Id as information field
|
||||||
|
|
||||||
const char HASS_DISCOVER_SENSOR_HUM[] PROGMEM =
|
const char HASS_DISCOVER_SENSOR_HUM[] PROGMEM =
|
||||||
",\"unit_of_meas\":\"%%\"," // %
|
",\"unit_of_meas\":\"%%\"," // %
|
||||||
"\"val_tpl\":\"{{value_json['%s'].Humidity}}\"," // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Humidity }}
|
"\"val_tpl\":\"{{value_json['%s'].Humidity}}\"," // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Humidity }}
|
||||||
|
@ -347,7 +351,7 @@ void HAssAnnounceSwitches(void)
|
||||||
// Send info about buttons
|
// Send info about buttons
|
||||||
char *tmp = Settings.switch_topic;
|
char *tmp = Settings.switch_topic;
|
||||||
Format(sw_topic, tmp, sizeof(sw_topic));
|
Format(sw_topic, tmp, sizeof(sw_topic));
|
||||||
if (strlen(sw_topic) != 0) {
|
if ((strlen(sw_topic) != 0) && strcmp(sw_topic, "0")) {
|
||||||
for (uint32_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
|
for (uint32_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
|
||||||
uint8_t switch_present = 0;
|
uint8_t switch_present = 0;
|
||||||
uint8_t toggle = 1;
|
uint8_t toggle = 1;
|
||||||
|
@ -376,7 +380,7 @@ void HAssAnnounceButtons(void)
|
||||||
// Send info about buttons
|
// Send info about buttons
|
||||||
char *tmp = Settings.button_topic;
|
char *tmp = Settings.button_topic;
|
||||||
Format(key_topic, tmp, sizeof(key_topic));
|
Format(key_topic, tmp, sizeof(key_topic));
|
||||||
if (strlen(key_topic) != 0) {
|
if ((strlen(key_topic) != 0) && strcmp(key_topic, "0")) {
|
||||||
for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
|
for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
|
||||||
uint8_t button_present = 0;
|
uint8_t button_present = 0;
|
||||||
uint8_t toggle = 1;
|
uint8_t toggle = 1;
|
||||||
|
@ -432,6 +436,9 @@ void HAssAnnounceSensor(const char* sensorname, const char* subsensortype)
|
||||||
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP.getChipId(), WiFi.macAddress().c_str());
|
TryResponseAppend_P(HASS_DISCOVER_DEVICE_INFO_SHORT, unique_id, ESP.getChipId(), WiFi.macAddress().c_str());
|
||||||
TryResponseAppend_P(HASS_DISCOVER_TOPIC_PREFIX, prefix);
|
TryResponseAppend_P(HASS_DISCOVER_TOPIC_PREFIX, prefix);
|
||||||
if (!strcmp_P(subsensortype, PSTR(D_JSON_TEMPERATURE))) {
|
if (!strcmp_P(subsensortype, PSTR(D_JSON_TEMPERATURE))) {
|
||||||
|
if (!strncmp_P(sensorname, "DS18B20-", 8)){
|
||||||
|
TryResponseAppend_P(HASS_DISCOVER_DS18X20_MULTI, state_topic, sensorname); // Add 'Id' as additional information
|
||||||
|
}
|
||||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_TEMP, TempUnit(), sensorname);
|
TryResponseAppend_P(HASS_DISCOVER_SENSOR_TEMP, TempUnit(), sensorname);
|
||||||
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_HUMIDITY))) {
|
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_HUMIDITY))) {
|
||||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_HUM, sensorname);
|
TryResponseAppend_P(HASS_DISCOVER_SENSOR_HUM, sensorname);
|
||||||
|
@ -449,8 +456,7 @@ void HAssAnnounceSensor(const char* sensorname, const char* subsensortype)
|
||||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_AMPERE, sensorname, subsensortype);
|
TryResponseAppend_P(HASS_DISCOVER_SENSOR_AMPERE, sensorname, subsensortype);
|
||||||
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_ILLUMINANCE))){
|
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_ILLUMINANCE))){
|
||||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_ILLUMINANCE, sensorname, subsensortype);
|
TryResponseAppend_P(HASS_DISCOVER_SENSOR_ILLUMINANCE, sensorname, subsensortype);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
TryResponseAppend_P(HASS_DISCOVER_SENSOR_ANY, sensorname, subsensortype);
|
TryResponseAppend_P(HASS_DISCOVER_SENSOR_ANY, sensorname, subsensortype);
|
||||||
}
|
}
|
||||||
TryResponseAppend_P(PSTR("}"));
|
TryResponseAppend_P(PSTR("}"));
|
||||||
|
@ -469,7 +475,7 @@ void HAssAnnounceSensors(void)
|
||||||
XsnsNextCall(FUNC_JSON_APPEND, hass_xsns_index); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
XsnsNextCall(FUNC_JSON_APPEND, hass_xsns_index); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089}
|
||||||
tele_period = tele_period_save;
|
tele_period = tele_period_save;
|
||||||
|
|
||||||
char sensordata[256]; // Copy because we need to write to mqtt_data
|
char sensordata[512]; // Copy because we need to write to mqtt_data
|
||||||
strlcpy(sensordata, mqtt_data, sizeof(sensordata));
|
strlcpy(sensordata, mqtt_data, sizeof(sensordata));
|
||||||
|
|
||||||
if (strlen(sensordata)) {
|
if (strlen(sensordata)) {
|
||||||
|
|
Loading…
Reference in New Issue