Rename HASS discovery string constants

This commit is contained in:
Erik 2018-12-22 13:21:04 +01:00
parent fd965eba09
commit c348848200
1 changed files with 40 additions and 40 deletions

View File

@ -21,7 +21,7 @@
#define XDRV_12 12
const char HASS_DISCOVER_RELAY_SHORT[] PROGMEM =
const char HASS_DISCOVER_RELAY[] PROGMEM =
"{\"name\":\"%s\"," // dualr2 1
"\"cmd_t\":\"%s\"," // cmnd/dualr2/POWER2
"\"stat_t\":\"%s\"," // stat/dualr2/RESULT (implies "\"optimistic\":\"false\",")
@ -33,7 +33,7 @@ const char HASS_DISCOVER_RELAY_SHORT[] PROGMEM =
"\"pl_avail\":\"" D_ONLINE "\"," // Online
"\"pl_not_avail\":\"" D_OFFLINE "\""; // Offline
const char HASS_DISCOVER_BUTTON_SWITCH_SHORT[] PROGMEM =
const char HASS_DISCOVER_BUTTON_SWITCH[] PROGMEM =
"{\"name\":\"%s\"," // dualr2 1 BTN
"\"stat_t\":\"%s\"," // cmnd/dualr2/POWER (implies "\"optimistic\":\"false\",")
// "\"value_template\":\"{{value_json.%s}}\"," // POWER2
@ -43,86 +43,86 @@ const char HASS_DISCOVER_BUTTON_SWITCH_SHORT[] PROGMEM =
"\"pl_avail\":\"" D_ONLINE "\"," // Online
"\"pl_not_avail\":\"" D_OFFLINE "\""; // Offline
const char HASS_DISCOVER_BUTTON_SWITCH_TOGGLE_SHORT[] PROGMEM =
const char HASS_DISCOVER_BUTTON_SWITCH_TOGGLE[] PROGMEM =
"%s,\"off_delay\":1"; // Hass has no support for TOGGLE, fake it by resetting to OFF after 1s
const char HASS_DISCOVER_BUTTON_SWITCH_ONOFF_SHORT[] PROGMEM =
const char HASS_DISCOVER_BUTTON_SWITCH_ONOFF[] PROGMEM =
"%s,\"frc_upd\":true," // In ON/OFF case, enable force_update to make automations work
"\"pl_off\":\"%s\""; // OFF
const char HASS_DISCOVER_LIGHT_DIMMER_SHORT[] PROGMEM =
const char HASS_DISCOVER_LIGHT_DIMMER[] PROGMEM =
"%s,\"bri_cmd_t\":\"%s\"," // cmnd/led2/Dimmer
"\"bri_stat_t\":\"%s\"," // stat/led2/RESULT
"\"bri_scl\":100," // 100%
"\"on_cmd_type\":\"brightness\"," // power on (first), power on (last), no power on (brightness)
"\"bri_val_tpl\":\"{{value_json." D_CMND_DIMMER "}}\"";
const char HASS_DISCOVER_LIGHT_COLOR_SHORT[] PROGMEM =
const char HASS_DISCOVER_LIGHT_COLOR[] PROGMEM =
"%s,\"rgb_cmd_t\":\"%s2\"," // cmnd/led2/Color2
"\"rgb_stat_t\":\"%s\"," // stat/led2/RESULT
"\"rgb_val_tpl\":\"{{value_json." D_CMND_COLOR ".split(',')[0:3]|join(',')}}\"";
const char HASS_DISCOVER_LIGHT_WHITE_SHORT[] PROGMEM =
const char HASS_DISCOVER_LIGHT_WHITE[] PROGMEM =
"%s,\"whit_val_cmd_t\":\"%s\"," // cmnd/led2/White
"\"whit_val_stat_t\":\"%s\"," // stat/led2/RESULT
"\"white_value_scale\":100," // (No abbreviation defined)
"\"whit_val_tpl\":\"{{ value_json.Channel[3] }}\"";
const char HASS_DISCOVER_LIGHT_CT_SHORT[] PROGMEM =
const char HASS_DISCOVER_LIGHT_CT[] PROGMEM =
"%s,\"clr_temp_cmd_t\":\"%s\"," // cmnd/led2/CT
"\"clr_temp_stat_t\":\"%s\"," // stat/led2/RESULT
"\"clr_temp_val_tpl\":\"{{value_json." D_CMND_COLORTEMPERATURE "}}\"";
const char HASS_DISCOVER_LIGHT_SCHEME_SHORT[] PROGMEM =
const char HASS_DISCOVER_LIGHT_SCHEME[] PROGMEM =
"%s,\"fx_cmd_t\":\"%s\"," // cmnd/led2/Scheme
"\"fx_stat_t\":\"%s\"," // stat/led2/RESULT
"\"fx_val_tpl\":\"{{value_json." D_CMND_SCHEME "}}\","
"\"fx_list\":[\"0\",\"1\",\"2\",\"3\",\"4\"]"; // string list with reference to scheme parameter.
const char HASS_DISCOVER_SENSOR_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR[] PROGMEM =
"{\"name\":\"%s\"," // dualr2 1 BTN
"\"stat_t\":\"%s\"," // cmnd/dualr2/POWER (implies "\"optimistic\":\"false\",")
"\"avty_t\":\"%s\"," // tele/dualr2/LWT
"\"pl_avail\":\"" D_ONLINE "\"," // Online
"\"pl_not_avail\":\"" D_OFFLINE "\""; // Offline
const char HASS_DISCOVER_SENSOR_TEMP_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_TEMP[] PROGMEM =
"%s,\"unit_of_meas\":\"°%c\"," // °C / °F
"\"val_tpl\":\"{{value_json['%s'].Temperature}}\""; // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Temperature }}
const char HASS_DISCOVER_SENSOR_HUM_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_HUM[] PROGMEM =
"%s,\"unit_of_meas\":\"%%\"," // %
"\"val_tpl\":\"{{value_json['%s'].Humidity}}\"," // "SI7021-14":{"Temperature":null,"Humidity":null} -> {{ value_json['SI7021-14'].Humidity }}
"\"dev_cla\":\"humidity\""; // humidity
const char HASS_DISCOVER_SENSOR_PRESS_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_PRESS[] PROGMEM =
"%s,\"unit_of_meas\":\"%s\"," // PressureUnit() setting
"\"val_tpl\":\"{{value_json['%s'].Pressure}}\"," // "BME280":{"Temperature":19.7,"Humidity":27.8,"Pressure":990.1} -> {{ value_json['BME280'].Pressure }}
"\"dev_cla\":\"pressure\""; // pressure
//ENERGY
const char HASS_DISCOVER_SENSOR_KWH_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_KWH[] PROGMEM =
"%s,\"unit_of_meas\":\"kWh\"," // kWh
"\"val_tpl\":\"{{value_json['%s'].%s}}\""; // "ENERGY":{"TotalStartTime":null,"Total":null,"Yesterday":null,"Today":null,"Power":null,"ApparentPower":null,"ReactivePower":null,"Factor":null,"Voltage":null,"Current":null} -> {{ value_json['ENERGY'].Total/Yesterday/Today }}
const char HASS_DISCOVER_SENSOR_WATT_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_WATT[] PROGMEM =
"%s,\"unit_of_meas\":\"W\"," // W
"\"val_tpl\":\"{{value_json['%s'].%s}}\""; // "ENERGY":{"TotalStartTime":null,"Total":null,"Yesterday":null,"Today":null,"Power":null,"ApparentPower":null,"ReactivePower":null,"Factor":null,"Voltage":null,"Current":null} -> {{ value_json['ENERGY'].POWER }}
const char HASS_DISCOVER_SENSOR_VOLTAGE_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_VOLTAGE[] PROGMEM =
"%s,\"unit_of_meas\":\"V\"," // V
"\"val_tpl\":\"{{value_json['%s'].%s}}\""; // "ENERGY":{"TotalStartTime":null,"Total":null,"Yesterday":null,"Today":null,"Power":null,"ApparentPower":null,"ReactivePower":null,"Factor":null,"Voltage":null,"Current":null} -> {{ value_json['ENERGY'].Voltage }}
const char HASS_DISCOVER_SENSOR_AMPERE_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_AMPERE[] PROGMEM =
"%s,\"unit_of_meas\":\"A\"," // A
"\"val_tpl\":\"{{value_json['%s'].%s}}\""; // "ENERGY":{"TotalStartTime":null,"Total":null,"Yesterday":null,"Today":null,"Power":null,"ApparentPower":null,"ReactivePower":null,"Factor":null,"Voltage":null,"Current":null} -> {{ value_json['ENERGY'].Current }}
const char HASS_DISCOVER_SENSOR_ANY_SHORT[] PROGMEM =
const char HASS_DISCOVER_SENSOR_ANY[] PROGMEM =
"%s,\"unit_of_meas\":\" \"," // " " As unit of measurement to get a value graph in Hass
"\"val_tpl\":\"{{value_json['%s'].%s}}\""; // "COUNTER":{"C1":0} -> {{ value_json['COUNTER'].C1 }}
const char HASS_DISCOVER_DEVICE_INFO_SHORT[] PROGMEM =
const char HASS_DISCOVER_DEVICE_INFO[] PROGMEM =
"%s,\"uniq_id\":\"%s\","
"\"device\":{\"identifiers\":[\"%06X\"],"
"\"name\":\"%s\","
@ -199,7 +199,7 @@ void HAssAnnounceRelayLight(void)
Shorten(&command_topic, prefix);
Shorten(&state_topic, prefix);
Shorten(&availability_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_RELAY_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_RELAY,
name, command_topic, state_topic, value_template, Settings.state_text[0], Settings.state_text[1], availability_topic);
if (is_light) {
@ -207,19 +207,19 @@ void HAssAnnounceRelayLight(void)
GetTopic_P(brightness_command_topic, CMND, mqtt_topic, D_CMND_DIMMER);
Shorten(&brightness_command_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_DIMMER_SHORT, mqtt_data, brightness_command_topic, state_topic);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_DIMMER, mqtt_data, brightness_command_topic, state_topic);
if (light_subtype >= LST_RGB) {
char *rgb_command_topic = stemp1;
GetTopic_P(rgb_command_topic, CMND, mqtt_topic, D_CMND_COLOR);
Shorten(&rgb_command_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_COLOR_SHORT, mqtt_data, rgb_command_topic, state_topic);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_COLOR, mqtt_data, rgb_command_topic, state_topic);
char *effect_command_topic = stemp1;
GetTopic_P(effect_command_topic, CMND, mqtt_topic, D_CMND_SCHEME);
Shorten(&effect_command_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_SCHEME_SHORT, mqtt_data, effect_command_topic, state_topic);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_SCHEME, mqtt_data, effect_command_topic, state_topic);
}
if (LST_RGBW == light_subtype) {
@ -227,18 +227,18 @@ void HAssAnnounceRelayLight(void)
GetTopic_P(white_temp_command_topic, CMND, mqtt_topic, D_CMND_WHITE);
Shorten(&white_temp_command_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_WHITE_SHORT, mqtt_data, white_temp_command_topic, state_topic);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_WHITE, mqtt_data, white_temp_command_topic, state_topic);
}
if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) {
char *color_temp_command_topic = stemp1;
GetTopic_P(color_temp_command_topic, CMND, mqtt_topic, D_CMND_COLORTEMPERATURE);
Shorten(&color_temp_command_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_CT_SHORT, mqtt_data, color_temp_command_topic, state_topic);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_LIGHT_CT, mqtt_data, color_temp_command_topic, state_topic);
}
}
snprintf_P(stemp1, sizeof(stemp1), kModules[Settings.module].name);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO_SHORT, mqtt_data,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO, mqtt_data,
unique_id, ESP.getChipId(),
Settings.friendlyname[0], stemp1, my_version, my_image, "Tasmota");
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_TOPIC_PREFIX, mqtt_data, prefix);
@ -282,13 +282,13 @@ void HAssAnnounceButtonSwitch(byte device, char* topic, byte present, byte key,
FindPrefix(state_topic, availability_topic, prefix);
Shorten(&state_topic, prefix);
Shorten(&availability_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH,
name, state_topic, Settings.state_text[toggle?2:1], availability_topic);
if (toggle) snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH_TOGGLE_SHORT, mqtt_data);
else snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH_ONOFF_SHORT, mqtt_data, Settings.state_text[0]);
if (toggle) snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH_TOGGLE, mqtt_data);
else snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_BUTTON_SWITCH_ONOFF, mqtt_data, Settings.state_text[0]);
snprintf_P(stemp1, sizeof(stemp1), kModules[Settings.module].name);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO_SHORT, mqtt_data,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO, mqtt_data,
unique_id, ESP.getChipId(),
Settings.friendlyname[0], stemp1, my_version, my_image, "Tasmota");
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_TOPIC_PREFIX, mqtt_data, prefix);
@ -385,36 +385,36 @@ void HAssAnnounceSensor(const char* sensorname, const char* subsensortype)
Shorten(&state_topic, prefix);
Shorten(&availability_topic, prefix);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR,
name, state_topic, availability_topic);
if (!strcmp_P(subsensortype, PSTR(D_JSON_TEMPERATURE))) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_TEMP_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_TEMP,
mqtt_data, TempUnit(), sensorname);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_HUMIDITY))) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_HUM_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_HUM,
mqtt_data, sensorname);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_PRESSURE))) {
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_PRESS_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_PRESS,
mqtt_data, PressureUnit().c_str(), sensorname);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_TOTAL)) || !strcmp_P(subsensortype, PSTR(D_JSON_TODAY)) || !strcmp_P(subsensortype, PSTR(D_JSON_YESTERDAY))){
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_KWH_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_KWH,
mqtt_data, sensorname, subsensortype);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_POWERUSAGE))){
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_WATT_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_WATT,
mqtt_data, sensorname, subsensortype);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_VOLTAGE))){
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_VOLTAGE_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_VOLTAGE,
mqtt_data, sensorname, subsensortype);
} else if (!strcmp_P(subsensortype, PSTR(D_JSON_CURRENT))){
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_AMPERE_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_AMPERE,
mqtt_data, sensorname, subsensortype);
}
else {
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_ANY_SHORT,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_SENSOR_ANY,
mqtt_data, sensorname, subsensortype);
}
snprintf_P(stemp1, sizeof(stemp1), kModules[Settings.module].name);
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO_SHORT, mqtt_data,
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_DEVICE_INFO, mqtt_data,
unique_id, ESP.getChipId(),
Settings.friendlyname[0], stemp1, my_version, my_image, "Tasmota");
snprintf_P(mqtt_data, sizeof(mqtt_data), HASS_DISCOVER_TOPIC_PREFIX, mqtt_data, prefix);