diff --git a/Code/src/config.h b/Code/src/config.h index ada76472..6e94e5c3 100644 --- a/Code/src/config.h +++ b/Code/src/config.h @@ -5,7 +5,7 @@ #include #endif #define DEVICE_NAME "layzspa" -#define FW_VERSION "2023-10-14-2335" +#define FW_VERSION "2023-10-17-2132" #define HA_PREFIX "homeassistant" #define PROM_NAMESPACE "layzspa" diff --git a/Code/src/ha.txt b/Code/src/ha.txt index 9d31078b..936e1bb5 100644 --- a/Code/src/ha.txt +++ b/Code/src/ha.txt @@ -5,94 +5,140 @@ Throws all kind of errors. String throws stack smashing. */ - void setupHA() { //HeapSelectIram ephemeral; //HeapSelectDram ephemeral; + /* Save RAM by storing strings in FLASH */ - const char* fs_dev = PSTR("dev"); - const char* fs_name = PSTR("name"); - const char* fs_uniq_id = PSTR("uniq_id"); - const char* fs_stat_t = PSTR("stat_t"); - const char* fs_avty_t = PSTR("avty_t"); - const char* fs_pl_avail = PSTR("pl_avail"); - const char* fs_pl_not_avail = PSTR("pl_not_avail"); - const char* fs_val_tpl = PSTR("val_tpl"); - const char* fs_cmd_t = PSTR("cmd_t"); - const char* fs_cmd_tpl = PSTR("cmd_tpl"); - const char* fs_conf_url = PSTR("configuration_url"); - const char* fs_connections = PSTR("connections"); - const char* fs_identifiers = PSTR("identifiers"); - const char* fs_manufacturer = PSTR("manufacturer"); - const char* fs_model = PSTR("model"); - const char* fs_sw_v = PSTR("sw_version"); - const char* fs_alive = PSTR("Alive"); - const char* fs_dead = PSTR("Dead"); - - const char* fs_max_temp = PSTR("max_temp"); - const char* fs_min_temp = PSTR("min_temp"); - const char* fs_precision = PSTR("precision"); - const char* fs_temp_unit = PSTR("temp_unit"); - const char* fs_modes = PSTR("modes"); - const char* fs_mode_cmd_t = PSTR("mode_cmd_t"); - const char* fs_mode_cmd_tpl = PSTR("mode_cmd_tpl"); - const char* fs_mode_stat_t = PSTR("mode_stat_t"); - const char* fs_mode_stat_tpl = PSTR("mode_stat_tpl"); - const char* fs_act_t = PSTR("act_t"); - const char* fs_act_tpl = PSTR("act_tpl"); - const char* fs_temp_stat_t = PSTR("temp_stat_t"); - const char* fs_temp_stat_tpl = PSTR("temp_stat_tpl"); - const char* fs_curr_temp_t = PSTR("curr_temp_t"); - const char* fs_curr_temp_tpl = PSTR("curr_temp_tpl"); - const char* fs_temp_cmd_t = PSTR("temp_cmd_t"); - const char* fs_temp_cmd_tpl = PSTR("temp_cmd_tpl"); - + PGM_P fs_dev = PSTR("dev"); + PGM_P fs_name = PSTR("name"); + PGM_P fs_uniq_id = PSTR("uniq_id"); + PGM_P fs_stat_t = PSTR("stat_t"); + PGM_P fs_avty_t = PSTR("avty_t"); + PGM_P fs_pl_avail = PSTR("pl_avail"); + PGM_P fs_pl_not_avail = PSTR("pl_not_avail"); + PGM_P fs_val_tpl = PSTR("val_tpl"); + PGM_P fs_cmd_t = PSTR("cmd_t"); + PGM_P fs_cmd_tpl = PSTR("cmd_tpl"); + PGM_P fs_conf_url = PSTR("configuration_url"); + PGM_P fs_connections = PSTR("connections"); + PGM_P fs_identifiers = PSTR("identifiers"); + PGM_P fs_manufacturer = PSTR("manufacturer"); + PGM_P fs_model = PSTR("model"); + PGM_P fs_sw_v = PSTR("sw_version"); + PGM_P fs_alive = PSTR("Alive"); + PGM_P fs_dead = PSTR("Dead"); + + PGM_P fs_max_temp = PSTR("max_temp"); + PGM_P fs_min_temp = PSTR("min_temp"); + PGM_P fs_precision = PSTR("precision"); + PGM_P fs_temp_unit = PSTR("temp_unit"); + PGM_P fs_modes = PSTR("modes"); + PGM_P fs_mode_cmd_t = PSTR("mode_cmd_t"); + PGM_P fs_mode_cmd_tpl = PSTR("mode_cmd_tpl"); + PGM_P fs_mode_stat_t = PSTR("mode_stat_t"); + PGM_P fs_mode_stat_tpl = PSTR("mode_stat_tpl"); + PGM_P fs_act_t = PSTR("act_t"); + PGM_P fs_act_tpl = PSTR("act_tpl"); + PGM_P fs_temp_stat_t = PSTR("temp_stat_t"); + PGM_P fs_temp_stat_tpl = PSTR("temp_stat_tpl"); + PGM_P fs_curr_temp_t = PSTR("curr_temp_t"); + PGM_P fs_curr_temp_tpl = PSTR("curr_temp_tpl"); + PGM_P fs_temp_cmd_t = PSTR("temp_cmd_t"); + PGM_P fs_temp_cmd_tpl = PSTR("temp_cmd_tpl"); + + PGM_P fs_expire_after = PSTR("expire_after"); + PGM_P fs_unit_of_meas = PSTR("unit_of_meas"); + /* ArduinoJson crashes when using flash strings on both sides - so here we pull them back to a String in RAM temporarily. - ArduinoJson wants a C-style string so we convert with c_str() */ - - const char* _dev = String(FPSTR(fs_dev)).c_str(); - const char* _name = String(FPSTR(fs_name)).c_str(); - const char* _uniq_id = String(FPSTR(fs_uniq_id)).c_str(); - const char* _stat_t = String(FPSTR(fs_stat_t)).c_str(); - const char* _avty_t = String(FPSTR(fs_avty_t)).c_str(); - const char* _pl_avail = String(FPSTR(fs_pl_avail)).c_str(); - const char* _pl_not_avail = String(FPSTR(fs_pl_not_avail)).c_str(); - const char* _val_tpl = String(FPSTR(fs_val_tpl)).c_str(); - const char* _cmd_t = String(FPSTR(fs_cmd_t)).c_str(); - const char* _cmd_tpl = String(FPSTR(fs_cmd_tpl)).c_str(); - const char* _conf_url = String(FPSTR(fs_conf_url)).c_str(); - const char* _connections = String(FPSTR(fs_connections)).c_str(); - const char* _identifiers = String(FPSTR(fs_identifiers)).c_str(); - const char* _manufacturer = String(FPSTR(fs_manufacturer)).c_str(); - const char* _model = String(FPSTR(fs_model)).c_str(); - const char* _sw_v = String(FPSTR(fs_sw_v)).c_str(); - const char* _alive = String(FPSTR(fs_alive)).c_str(); - const char* _dead = String(FPSTR(fs_dead)).c_str(); - - const char* _max_temp = String(FPSTR(fs_max_temp)).c_str(); - const char* _min_temp = String(FPSTR(fs_min_temp)).c_str(); - const char* _precision = String(FPSTR(fs_precision)).c_str(); - const char* _temp_unit = String(FPSTR(fs_temp_unit)).c_str(); - const char* _modes = String(FPSTR(fs_modes)).c_str(); - const char* _mode_cmd_t = String(FPSTR(fs_mode_cmd_t)).c_str(); - const char* _mode_cmd_tpl = String(FPSTR(fs_mode_cmd_tpl)).c_str(); - const char* _mode_stat_t = String(FPSTR(fs_mode_stat_t)).c_str(); - const char* _mode_stat_tpl = String(FPSTR(fs_mode_stat_tpl)).c_str(); - const char* _act_t = String(FPSTR(fs_act_t)).c_str(); - const char* _act_tpl = String(FPSTR(fs_act_tpl)).c_str(); - const char* _temp_stat_t = String(FPSTR(fs_temp_stat_t)).c_str(); - const char* _temp_stat_tpl = String(FPSTR(fs_temp_stat_tpl)).c_str(); - const char* _curr_temp_t = String(FPSTR(fs_curr_temp_t)).c_str(); - const char* _curr_temp_tpl = String(FPSTR(fs_curr_temp_tpl)).c_str(); - const char* _temp_cmd_t = String(FPSTR(fs_temp_cmd_t)).c_str(); - const char* _temp_cmd_tpl = String(FPSTR(fs_temp_cmd_tpl)).c_str(); - + so here we pull them back to a String in RAM temporarily. */ + + char _dev[32]; + char _name[32]; + char _uniq_id[32]; + char _stat_t[32]; + char _avty_t[32]; + char _pl_avail[32]; + char _pl_not_avail[32]; + char _val_tpl[32]; + char _cmd_t[32]; + char _cmd_tpl[32]; + char _conf_url[32]; + char _connections[32]; + char _identifiers[32]; + char _manufacturer[32]; + char _model[32]; + char _sw_v[32]; + char _alive[32]; + char _dead[32]; + + char _max_temp[32]; + char _min_temp[32]; + char _precision[32]; + char _temp_unit[32]; + char _modes[32]; + char _mode_cmd_t[32]; + char _mode_cmd_tpl[32]; + char _mode_stat_t[32]; + char _mode_stat_tpl[32]; + char _act_t[32]; + char _act_tpl[32]; + char _temp_stat_t[32]; + char _temp_stat_tpl[32]; + char _curr_temp_t[32]; + char _curr_temp_tpl[32]; + char _temp_cmd_t[32]; + char _temp_cmd_tpl[32]; + + char _expire_after[32]; + char _unit_of_meas[32]; + + + + strcpy_P(_dev, fs_dev); + strcpy_P(_name, fs_name); + strcpy_P(_uniq_id, fs_uniq_id); + strcpy_P(_stat_t, fs_stat_t); + strcpy_P(_avty_t, fs_avty_t); + strcpy_P(_pl_avail, fs_pl_avail); + strcpy_P(_pl_not_avail, fs_pl_not_avail); + strcpy_P(_val_tpl, fs_val_tpl); + strcpy_P(_cmd_t, fs_cmd_t); + strcpy_P(_cmd_tpl, fs_cmd_tpl); + strcpy_P(_conf_url, fs_conf_url); + strcpy_P(_connections, fs_connections); + strcpy_P(_identifiers, fs_identifiers); + strcpy_P(_manufacturer, fs_manufacturer); + strcpy_P(_model, fs_model); + strcpy_P(_sw_v, fs_sw_v); + strcpy_P(_alive, fs_alive); + strcpy_P(_dead, fs_dead); + + strcpy_P(_max_temp, fs_max_temp); + strcpy_P(_min_temp, fs_min_temp); + strcpy_P(_precision, fs_precision); + strcpy_P(_temp_unit, fs_temp_unit); + strcpy_P(_modes, fs_modes); + strcpy_P(_mode_cmd_t, fs_mode_cmd_t); + strcpy_P(_mode_cmd_tpl, fs_mode_cmd_tpl); + strcpy_P(_mode_stat_t, fs_mode_stat_t); + strcpy_P(_mode_stat_tpl, fs_mode_stat_tpl); + strcpy_P(_act_t, fs_act_t); + strcpy_P(_act_tpl, fs_act_tpl); + strcpy_P(_temp_stat_t, fs_temp_stat_t); + strcpy_P(_temp_stat_tpl, fs_temp_stat_tpl); + strcpy_P(_curr_temp_t, fs_curr_temp_t); + strcpy_P(_curr_temp_tpl, fs_curr_temp_tpl); + strcpy_P(_temp_cmd_t, fs_temp_cmd_t); + strcpy_P(_temp_cmd_tpl, fs_temp_cmd_tpl); + + strcpy_P(_expire_after, fs_expire_after); + strcpy_P(_unit_of_meas, fs_unit_of_meas); /* DEVICE */ /* @@ -113,8 +159,8 @@ int maxtemp, mintemp; maxtemp = 104; mintemp = 68; - DynamicJsonDocument devicedoc(512); - devicedoc[(_dev)][(_conf_url)] = F("http://") + WiFi.localIP().toString(); + DynamicJsonDocument devicedoc(1024); + devicedoc[_dev][_conf_url] = F("http://") + WiFi.localIP().toString(); devicedoc[(_dev)][(_connections)].add(serialized("[\"mac\",\"" + WiFi.macAddress()+"\"]" )); devicedoc[(_dev)][(_identifiers)] = mychipid; devicedoc[(_dev)][(_manufacturer)] = F("Visualapproach"); @@ -123,8 +169,7 @@ devicedoc[(_dev)][(_sw_v)] = FW_VERSION; - DynamicJsonDocument doc(1536); - + DynamicJsonDocument doc(2048); /************/ /* NUMBER */ /************/ @@ -259,7 +304,7 @@ doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_ssid")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/other"); doc[(_val_tpl)] = F("{{ value_json.SSID }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -285,9 +330,9 @@ doc[(_name)] = mqttBaseTopic + F(" rssi"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_rssi")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/other"); - doc["unit_of_meas"] = F("dBm"); + doc[_unit_of_meas] = F("dBm"); doc[(_val_tpl)] = F("{{ value_json.RSSI }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -315,7 +360,7 @@ doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_ip")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/other"); doc[(_val_tpl)] = F("{{ value_json.IP }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -366,7 +411,7 @@ doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_error")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_val_tpl)] = F("{{ value_json.ERR }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -394,9 +439,9 @@ doc[(_name)] = mqttBaseTopic + F(" time to ready"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_time_to_ready")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("hours"); + doc[_unit_of_meas] = F("hours"); doc[(_val_tpl)] = F("{{ value_json.T2R }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:clock"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -425,7 +470,7 @@ doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_rs")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); doc[(_val_tpl)] = F("{{ value_json.RS }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -453,11 +498,11 @@ doc[(_name)] = mqttBaseTopic + F(" energy"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_energy")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("kWh"); + doc[_unit_of_meas] = F("kWh"); doc[(_val_tpl)] = F("{{ value_json.KWH | round(3) }}"); doc["dev_cla"] = F("energy"); doc["state_class"] = F("total_increasing"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:flash"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -484,11 +529,11 @@ doc[(_name)] = mqttBaseTopic + F(" today"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_today")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("kWh"); + doc[_unit_of_meas] = F("kWh"); doc[(_val_tpl)] = F("{{ value_json.KWHD | round(3) }}"); doc["dev_cla"] = F("energy"); doc["state_class"] = F("total_increasing"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:flash"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -516,11 +561,11 @@ doc[(_name)] = mqttBaseTopic + F(" power"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_power")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("W"); + doc[_unit_of_meas] = F("W"); doc[(_val_tpl)] = F("{{ value_json.WATT | int }}"); doc["dev_cla"] = F("power"); doc["state_class"] = F("measurement"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:flash"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -548,9 +593,9 @@ doc[(_name)] = mqttBaseTopic + F(" chlorine age"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_chlorine_age")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("days"); + doc[_unit_of_meas] = F("days"); doc[(_val_tpl)] = F("{{ ( ( (now().timestamp()|int) - value_json.CLTIME|int)/3600/24) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("hass:hand-coin-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -578,9 +623,9 @@ doc[(_name)] = mqttBaseTopic + F(" filter age"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_filter_age")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("days"); + doc[_unit_of_meas] = F("days"); doc[(_val_tpl)] = F("{{ ( ( (now().timestamp()|int) - value_json.FTIME|int)/3600/24) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("hass:air-filter"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -607,9 +652,9 @@ doc[(_name)] = mqttBaseTopic + F(" uptime"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_uptime")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("days"); + doc[_unit_of_meas] = F("days"); doc[(_val_tpl)] = F("{{ ( (value_json.UPTIME|int)/3600/24) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:clock-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -637,9 +682,9 @@ doc[(_name)] = mqttBaseTopic + F(" pump time"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_pumptime")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("hours"); + doc[_unit_of_meas] = F("hours"); doc[(_val_tpl)] = F("{{ ( (value_json.PUMPTIME|int)/3600) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:clock-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -667,9 +712,9 @@ doc[(_name)] = mqttBaseTopic + F(" heater time"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_heatertime")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("hours"); + doc[_unit_of_meas] = F("hours"); doc[(_val_tpl)] = F("{{ ( (value_json.HEATINGTIME|int)/3600) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:clock-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -697,9 +742,9 @@ doc[(_name)] = mqttBaseTopic + F(" air time"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_airtime")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/times"); - doc["unit_of_meas"] = F("hours"); + doc[_unit_of_meas] = F("hours"); doc[(_val_tpl)] = F("{{ ( (value_json.AIRTIME|int)/3600) | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:clock-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -727,9 +772,9 @@ doc[(_name)] = mqttBaseTopic + F(" temp (F)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_temp_f")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°F"; + doc[_unit_of_meas] = "°F"; doc[(_val_tpl)] = F("{{ value_json.TMPF }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -757,9 +802,9 @@ doc[(_name)] = mqttBaseTopic + F(" temp (C)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_temp_c")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°C"; + doc[_unit_of_meas] = "°C"; doc[(_val_tpl)] = F("{{ value_json.TMPC }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -787,9 +832,9 @@ doc[(_name)] = mqttBaseTopic + F(" virtual temp (F)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_virtual_temp_f")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°F"; + doc[_unit_of_meas] = "°F"; doc[(_val_tpl)] = F("{{ value_json.VTMF | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -817,9 +862,9 @@ doc[(_name)] = mqttBaseTopic + F(" virtual temp (C)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_virtual_temp_c")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°C"; + doc[_unit_of_meas] = "°C"; doc[(_val_tpl)] = F("{{ value_json.VTMC | round(2) }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -847,9 +892,9 @@ doc[(_name)] = mqttBaseTopic + F(" target temp (F)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_target_temp_f")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°F"; + doc[_unit_of_meas] = "°F"; doc[(_val_tpl)] = F("{{ value_json.TGTF }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -878,9 +923,9 @@ doc[(_name)] = mqttBaseTopic + F(" target temp (C)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_target_temp_c")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°C"; + doc[_unit_of_meas] = "°C"; doc[(_val_tpl)] = F("{{ value_json.TGTC }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -908,9 +953,9 @@ doc[(_name)] = mqttBaseTopic + F(" ambient temp (C)"); doc[(_uniq_id)] = F("sensor.") + mqttBaseTopic + F("_amb_temp_c")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc["unit_of_meas"] = "°C"; + doc[_unit_of_meas] = "°C"; doc[(_val_tpl)] = F("{{ value_json.AMBC }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -940,15 +985,15 @@ topic += F("/sensor/"); topic += mqttBaseTopic; topic += F("_lock/config"); - doc[(_name)] = mqttBaseTopic + F(" lock"); - doc[(_uniq_id)] = F("binary_sensor.") + mqttBaseTopic + F("_lock")+mychipid; - doc[(_stat_t)] = mqttBaseTopic+F("/message"); - doc[(_val_tpl)] = F("{% if value_json.LCK == 1 %}OFF{% else %}ON{% endif %}"); + doc[_name] = mqttBaseTopic + F(" lock"); + doc[_uniq_id] = F("binary_sensor.") + mqttBaseTopic + F("_lock")+mychipid; + doc[_stat_t] = mqttBaseTopic+F("/message"); + doc[_val_tpl] = F("{% if value_json.LCK == 1 %}OFF{% else %}ON{% endif %}"); doc["dev_cla"] = F("lock"); - doc["expire_after"] = 700; - doc[(_avty_t)] = mqttBaseTopic+F("/Status"); - doc[(_pl_avail)] = _alive; - doc[(_pl_not_avail)] = _dead; + doc[_expire_after] = 700; + doc[_avty_t] = mqttBaseTopic+F("/Status"); + doc[_pl_avail] = _alive; + doc[_pl_not_avail] = _dead; if (serializeJson(doc, payload) == 0) { // Serial.println(F("Failed to serialize HA message!")); @@ -974,7 +1019,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_val_tpl)] = F("{% if value_json.RED == 1 %}ON{% else %}OFF{% endif %}"); doc["dev_cla"] = F("heat"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; doc[(_pl_not_avail)] = _dead; @@ -1002,7 +1047,7 @@ doc[(_uniq_id)] = F("binary_sensor.") + mqttBaseTopic + F("_ready")+mychipid; doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_val_tpl)] = F("{% if value_json.TMP > 30 %}{% if value_json.TMP >= value_json.TGT-1 %}ON{% else %}OFF{% endif %}{% else %}OFF{% endif %}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:hot-tub"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1067,7 +1112,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{% if value_json.RED == 1 %}1{% elif value_json.GRN == 1 %}1{% else %}0{% endif %}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:radiator"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1101,7 +1146,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{{ value_json.HJT }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:hydro-power"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1135,7 +1180,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{{ value_json.AIR }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:chart-bubble"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1169,7 +1214,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{{ value_json.FLT }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:pump"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1203,7 +1248,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{{ value_json.UNT }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:circle-outline"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive; @@ -1237,7 +1282,7 @@ doc[(_stat_t)] = mqttBaseTopic+F("/message"); doc[(_cmd_t)] = mqttBaseTopic+F("/command"); doc[(_val_tpl)] = F("{{ value_json.GOD }}"); - doc["expire_after"] = 700; + doc[_expire_after] = 700; doc["icon"] = F("mdi:steering"); doc[(_avty_t)] = mqttBaseTopic+F("/Status"); doc[(_pl_avail)] = _alive;