ESP8266 и MQTT discovery homeassistant

Добрый день, пытаюсь написать код для MQTT discovery homeassistant для ESP8266 по отдельности элементы работают, а когда собрал в один проект, возникла следующая проблема код:

    Serial.begin(9600, SERIAL_8E1); // Настраиваем UART
    HAMqttDiscoveryClimate hamdhGreeAC(hamdhGree);
  hamdhGreeAC.setDeviceNameMin("gree_ac");
  hamdhGreeAC.setModeCommandTemplate("{\"acgree_mode\": \"{{ value }}\"}");
  hamdhGreeAC.setFanModeCommandTemplate("{\"acgree_fan_mode\": \"{{ value }}\"}");
  hamdhGreeAC.setSwingModeCommandTemplate("{\"acgree_swing_mode\": \"{{ value }}\"}");
  hamdhGreeAC.setTemperatureCommandTemplate("{\"acgree_temperature\": \"{{ value }}\"}");
  hamdhGreeAC.setfanModeStateTemplate("{{ value_json.acgree_fan_mode }}");
  hamdhGreeAC.setModeStateTemplate("{{ value_json.acgree_mode }}");
  hamdhGreeAC.setSwingModeStateTemplate("{{ value_json.acgree_swing_mode }}");
  hamdhGreeAC.setTemperatureStateTemplate("{{ value_json.acgree_temperature }}");
  String modes[10] = {"auto", "cool", "dry", "fan_only", "heat", "off", "", "", "", ""};
  String swingModes[10] = {"off", "vertical", "horizontal", "both", "", "", "", "", "", ""};
  String fanModes[10] = {"low", "medium", "high", "", "", "", "", "", "", ""};
  hamdhGreeAC.setModes(modes);
  hamdhGreeAC.setSwingModes(swingModes);
  hamdhGreeAC.setFanModes(fanModes);

  hamdhGreeAC.construct();

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  Serial.println("Before delay!!!");
  Serial.println(hamdhGreeAC.getMqttDiscoveryMesg());
  delay(4000);

  Serial.println("\nYou need to publish:\n");
Serial.println(hamdhGreeAC.getMqttDiscoveryMesg());
	Serial.println("\nTo:\n");
	Serial.println(hamdhGreeAC.getMqttDiscoveryConfigTopic());

Выполняется нормально, только, если wifi не подключен

Before delay!!!
{"availability":[{"topic":"homegear/sn001/state"}],"device":{"identifiers":["homegear_ir_ac001"],"manufacturer":"Gree","model":"Gree AC","name":"ac001","sw_version":"HomeGear 1.0","via_device":"homegear_sn001"},"json_attributes_topic":"homegear_ir/ac001/attr","name":"ac001 gree_ac","unique_id":"ac001_gree_ac_homegear_ir","fan_mode_command_template":"{\"acgree_fan_mode\": \"{{ value }}\"}","fan_mode_command_topic":"homegear_ir/ac001/ctrl","mode_command_template":"{\"acgree_mode\": \"{{ value }}\"}","mode_command_topic":"homegear_ir/ac001/ctrl","swing_mode_command_template":"{\"acgree_swing_mode\": \"{{ value }}\"}","swing_mode_command_topic":"homegear_ir/ac001/ctrl","temperature_command_template":"{\"acgree_temperature\": \"{{ value }}\"}","temperature_command_topic":"homegear_ir/ac001/ctrl","fan_mode_state_template":"{{ value_json.acgree_fan_mode }}","fan_mode_state_topic":"homegear_ir/ac001/attr","mode_state_template":"{{ value_json.acgree_mode }}","mode_state_topic":"homegear_ir/ac001/attr","swing_mode_state_template":"{{ value_json.acgree_swing_mode }}","swing_mode_state_topic":"homegear_ir/ac001/attr","temperature_state_template":"{{ value_json.acgree_temperature }}","temperature_state_topic":"homegear_ir/ac001/attr","modes":["auto","cool","dry","fan_only","heat","off"],"swing_modes":["off","vertical","horizontal","both"],"fan_modes":["low","medium","high"],"max_temp":31,"min_temp":16,"temperature_unit":"C"}

WiFi connected
IP address: 

You need to publish:



To:

homeassistant/climate/ac001/gree_ac/config

hamdhGreeAC.getMqttDiscoveryMesg() ничего не возвращает после подключения по Wifi, возможно мне кто-нибудь сможет объяснить из-за чего такое возможно?

Использую библиотеку HAMqttDiscoveryHandler
https://docs.arduino.cc/libraries/hamqttdiscoveryhandler/

это не код. В нем нет ни setup() ни loop()
Выкладывайте код ПОЛНОСТЬЮ

@mcshel
вы пометили тему как решенную - значит у вас больше нет вопросов?

Пишите для Андроида на питоне. Так будет правильней.