//#include #include #include #include // My Libraries #include #include #include #include OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); byte glycol_ds18b20[8] = {0x28,0xFF,0x64,0x0E,0x7F,0x57,0x09,0x66}; byte fermA_ds18b20[8] = {0x28,0xFF,0x64,0x0E,0x7F,0x57,0x09,0x66}; byte fermB_ds18b20[8] = {0x28,0xFF,0x64,0x0E,0x7F,0x57,0x09,0x66}; String chiller_state = "idle"; int tank_setpoint = 28; WiFiClient net; ControlDevice DEVICE_LIST[3]; int TOTAL_DEVICES = 0; auto chipid = String(ESP.getChipId(), HEX); Communicator hass_comm = Communicator(net); unsigned long lastMillis; unsigned long currentMillis; void mqttCallback(char *topic, byte *payload, unsigned int length) { payload[length] = '\0'; for (int i=0;i entity; entity["uniq_id"] = chipid + "_" + name_slug; entity["name"] = name; entity["value_template"] = "{{ value }}"; entity["temp_unit"] = "F"; entity["max_temp"] = 100; entity["min_temp"] = 0; entity["swing_mode_stat_t"] = topic_root + SWING_STATE; device.swing_topic = topic_root + SWING_STATE; entity["act_t"] = topic_root + ACTION_TPC; entity["act_tpl"] = "{{ value }}"; device.action_topic = topic_root + ACTION_TPC; // Mode setup entity["mode_cmd_t"] = topic_root + MODE_SET; Mode mode = {topic_root + MODE_SET, topic_root + MODE_STATE, "off"}; device.mode = mode; entity["mode_cmd_tpl"] = "{{ value }}"; entity["mode_stat_t"] = topic_root + MODE_STATE; JsonArray modes = entity.createNestedArray("modes"); modes.add("off"); modes.add("cool"); entity["temp_cmd_t"] = topic_root + TEMP_SET; SetPoint temp = {topic_root + TEMP_SET,topic_root + TEMP_STATE,70}; device.setpoints[setpoint_count] = temp; setpoint_count++; entity["temp_cmd_tpl"] = "{{ value }}"; entity["temp_stat_t"] = topic_root + TEMP_STATE; entity["curr_temp_t"] = topic_root + TEMP_CURRENT; entity["curr_temp_tpl"] = "{{ value }}"; device.current_temp_topic= topic_root + TEMP_CURRENT; if (multimode == true) { device.dual = true; entity["temp_hi_cmd_t"] = topic_root + TEMP_HI_SET; SetPoint temp_hi = {topic_root + TEMP_HI_SET, topic_root + TEMP_HI_STATE, 70}; device.setpoints[setpoint_count] = temp_hi; setpoint_count++; entity["temp_hi_cmd_tpl"] = "{{ value }}"; entity["temp_hi_stat_t"] = topic_root + TEMP_HI_STATE; entity["temp_lo_cmd_t"] = topic_root + TEMP_LO_SET; SetPoint temp_lo = {topic_root + TEMP_LO_SET, topic_root + TEMP_LO_STATE, 70}; device.setpoints[setpoint_count] = temp_lo; setpoint_count++; entity["temp_lo_cmd_tpl"] = "{{ value }}"; entity["temp_lo_stat_t"] = topic_root + TEMP_LO_STATE; modes.add("heat"); modes.add("auto"); } JsonObject dev = entity.createNestedObject("dev"); dev["name"] = DEVICE_NAME; dev["mdl"] = DEVICE_MDL; dev["sw"] = DEVICE_SW; dev["mf"] = DEVICE_MF; JsonArray ids = dev.createNestedArray("ids"); ids.add(chipid); //dev["ids"] = "[\"" + chipid +"\"]"; DEVICE_LIST[TOTAL_DEVICES] = device; TOTAL_DEVICES++; hass_comm.mqtt_discovery(config_topic, entity); } void SendUpdate() { int setpoint_count = 0; float device_temp; for (int i=0;i= 10000) { sensors.requestTemperatures(); SendUpdate(); lastMillis = currentMillis; } delay(100); hass_comm.loop(); }