22# #### TX Ultimate Easy for ESPHome #####
33# #### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy #####
44# ###################################################################################################
5- # #### Purpose: ESPHome Core - Common #####
5+ # #### Purpose: ESPHome - Common #####
66# ###################################################################################################
77# #### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo #####
88# ###################################################################################################
@@ -29,14 +29,14 @@ substitutions:
2929
3030 DUMP_CONFIG_CALLER_DELAY : 5s # Delay to dump config after requested
3131
32- TAG_CORE_COMMON : core .common
32+ TAG_COMMON : tx_ultimate_easy .common
3333
3434api :
3535 id : api_server
36+ homeassistant_services : true
3637 on_client_connected :
3738 then :
3839 - script.execute : dump_config_caller
39- - script.execute : publish_device_info
4040
4141binary_sensor :
4242 - id : bs_pending_restart
@@ -73,18 +73,23 @@ esp32:
7373 flash_size : 8MB
7474 framework :
7575 type : esp-idf
76+ advanced :
77+ loop_task_stack_size : 16384
78+ sdkconfig_options :
79+ CONFIG_ESP32_REV_MIN_3 : y
7680
7781esphome :
7882 name : ${name}
7983 friendly_name : ${friendly_name}
8084 comment : TX Ultimate Easy
81- min_version : 2025.8 .0
85+ min_version : 2025.11 .0
8286 project :
8387 name : " edwardtfn.tx_ultimate_easy"
8488 version : ${version}
8589 platformio_options :
8690 build_flags :
87- - -D TX_ULTIMATE_EASY_CORE_COMMON
91+ - -D TX_ULTIMATE_EASY_COMMON
92+ - -D TX_ULTIMATE_EASY_FIRMWARE_VERSION="${version}"
8893
8994 on_boot :
9095 - priority : 1000 # Very early in boot process
@@ -145,13 +150,7 @@ script:
145150 then :
146151 - lambda : |-
147152 // Send event to Home Assistant
148- esphome::api::CustomAPIDevice ha_event;
149- ha_event.fire_homeassistant_event("${EVENT_NAME}", {
150- {"device_name", id(tx_device_name).state.c_str()},
151- {"firmware", "${version}"},
152- {"domain", "boot"},
153- {"type", type.c_str()}
154- });
153+ esphome::tx_ultimate_easy::fire_ha_event("boot", type.c_str(), {});
155154
156155 - id : boot_done
157156 mode : restart
@@ -174,6 +173,7 @@ script:
174173 # - HW Buttons
175174 # - HW Relays
176175 # - HW Touch
176+ - script.execute : update_device_name
177177 - script.execute :
178178 id : api_send_ha_event_boot
179179 type : start
@@ -182,16 +182,15 @@ script:
182182 - lambda : return sl_tx_model_format->active_index().has_value();
183183 - lambda : return sl_tx_model_gang->active_index().has_value();
184184 - lambda : |-
185- id(is_us_model) = (sl_tx_model_format->state == "${TX_MODEL_FORMAT_US_TEXT}");
185+ id(is_us_model) = strcmp (sl_tx_model_format->current_option(), "${TX_MODEL_FORMAT_US_TEXT}") == 0 ;
186186 id(gang_count) = sl_tx_model_gang->active_index().value() + 1;
187187 if (id(gang_count) < 1 || id(gang_count) > 4) {
188- ESP_LOGE("${TAG_CORE_COMMON }", "Invalid number of gangs: %" PRIu8, id(gang_count));
188+ ESP_LOGE("${TAG_COMMON }", "Invalid number of gangs: %" PRIu8, id(gang_count));
189189 }
190190
191191 - id : boot_sequence
192192 mode : restart
193193 then :
194- - script.execute : publish_device_info
195194 - binary_sensor.template.publish :
196195 id : bs_pending_restart
197196 state : false
@@ -202,43 +201,43 @@ script:
202201 # Extended by all modules
203202 - lambda : |-
204203 // Device identification
205- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Device friendly name: ${friendly_name}");
206- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Device name: ${name}");
207- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Device name (HA): %s", tx_device_name->state .c_str());
208- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Device hostname: %s", App.get_name().c_str());
204+ ESP_LOGCONFIG("${TAG_COMMON }", "Device friendly name: ${friendly_name}");
205+ ESP_LOGCONFIG("${TAG_COMMON }", "Device name: ${name}");
206+ ESP_LOGCONFIG("${TAG_COMMON }", "Device name (HA): %s", esphome::tx_ultimate_easy::cached_device_name .c_str());
207+ ESP_LOGCONFIG("${TAG_COMMON }", "Device hostname: %s", App.get_name().c_str());
209208
210209 dump_config_versions->execute();
211210
212211 // Framework detection
213212 #ifdef USE_ARDUINO
214- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Framework: Arduino");
213+ ESP_LOGCONFIG("${TAG_COMMON }", "Framework: Arduino");
215214 #elif defined(USE_ESP_IDF)
216- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Framework: ESP-IDF");
215+ ESP_LOGCONFIG("${TAG_COMMON }", "Framework: ESP-IDF");
217216 #else
218- ESP_LOGW("${TAG_CORE_COMMON }", "Framework: UNKNOWN");
217+ ESP_LOGW("${TAG_COMMON }", "Framework: UNKNOWN");
219218 #endif
220219
221220 // Model configuration
222- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Model format (selected): %s",
223- sl_tx_model_format->state.c_str ());
224- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Model format (detected): %s",
221+ ESP_LOGCONFIG("${TAG_COMMON }", "Model format (selected): %s",
222+ sl_tx_model_format->current_option ());
223+ ESP_LOGCONFIG("${TAG_COMMON }", "Model format (detected): %s",
225224 id(is_us_model) ? "US" : "EU");
226- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Gangs (selected): %s",
227- sl_tx_model_gang->state.c_str ());
228- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Gangs (detected): %" PRIu8 "-Gang%s",
225+ ESP_LOGCONFIG("${TAG_COMMON }", "Gangs (selected): %s",
226+ sl_tx_model_gang->current_option ());
227+ ESP_LOGCONFIG("${TAG_COMMON }", "Gangs (detected): %" PRIu8 "-Gang%s",
229228 id(gang_count), id(gang_count) > 1 ? "s" : "");
230229
231230 // Boot completion status
232231 if (bs_boot_completed->state)
233- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Boot completed: Yes");
232+ ESP_LOGCONFIG("${TAG_COMMON }", "Boot completed: Yes");
234233 else
235- ESP_LOGW("${TAG_CORE_COMMON }", "Boot completed: NO");
234+ ESP_LOGW("${TAG_COMMON }", "Boot completed: NO");
236235
237236 // System state
238237 if (bs_pending_restart->state)
239- ESP_LOGW("${TAG_CORE_COMMON }", "Pending restart: YES");
238+ ESP_LOGW("${TAG_COMMON }", "Pending restart: YES");
240239 else
241- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "Pending restart: No");
240+ ESP_LOGCONFIG("${TAG_COMMON }", "Pending restart: No");
242241
243242 - id : dump_config_caller
244243 mode : restart
@@ -263,17 +262,10 @@ script:
263262 then :
264263 - lambda : |-
265264 // Version information
266- ESP_LOGCONFIG("${TAG_CORE_COMMON }", "TX Ultimate firmware version: ${version}");
265+ ESP_LOGCONFIG("${TAG_COMMON }", "TX Ultimate firmware version: ${version}");
267266 // ESPHome builder information
268- ESP_LOGCONFIG("${TAG_CORE_COMMON}", "ESPHome builder: " ESPHOME_VERSION);
269- ESP_LOGCONFIG("${TAG_CORE_COMMON}", "ESPHome build timestamp: %s", App.get_compilation_time().c_str());
270-
271- - id : publish_device_info
272- mode : restart
273- then :
274- - lambda : |-
275- tx_fw_version->publish_state("${version}");
276- tx_device_name->publish_state(App.get_name().c_str());
267+ ESP_LOGCONFIG("${TAG_COMMON}", "ESPHome builder: " ESPHOME_VERSION);
268+ ESP_LOGCONFIG("${TAG_COMMON}", "ESPHome build timestamp: %s", App.get_compilation_time().c_str());
277269
278270 - id : restore_from_nvs
279271 mode : single
@@ -287,6 +279,16 @@ script:
287279 if (id(gang_count) < 1 || id(gang_count) > 4) return 0; // default to 1-Gang
288280 return static_cast<uint8_t>(id(gang_count)) - 1;
289281
282+ - id : update_device_name
283+ mode : single
284+ then :
285+ - lambda : |-
286+ if (esphome::tx_ultimate_easy::cached_device_name.empty()) {
287+ esphome::tx_ultimate_easy::initialize_cached_device_name(App.get_name());
288+ ESP_LOGI("${TAG_COMMON}", "Device name: %s", esphome::tx_ultimate_easy::cached_device_name.c_str());
289+ tx_device_name->publish_state(esphome::tx_ultimate_easy::cached_device_name);
290+ }
291+
290292select :
291293 - id : sl_tx_model_format
292294 name : Model (Format)
@@ -303,10 +305,8 @@ select:
303305 icon : mdi:tablet-cellphone
304306 on_value :
305307 then :
306- - binary_sensor.template.publish :
307- id : bs_pending_restart
308- state : true
309308 - lambda : |-
309+ bs_pending_restart->publish_state(true);
310310 id(is_us_model) = (x == "${TX_MODEL_FORMAT_US_TEXT}");
311311
312312 - id : sl_tx_model_gang
@@ -326,10 +326,8 @@ select:
326326 icon : mdi:dip-switch
327327 on_value :
328328 then :
329- - binary_sensor.template.publish :
330- id : bs_pending_restart
331- state : true
332329 - lambda : |-
330+ bs_pending_restart->publish_state(true);
333331 id(gang_count) = static_cast<uint8_t>(i) + 1;
334332 tx_ultimate->set_gang_count(id(gang_count));
335333
@@ -353,26 +351,18 @@ text_sensor:
353351 disabled_by_default : false
354352 update_interval : never
355353 lambda : |-
356- return {"${name}"};
357- filters :
358- - lambda : |-
359- const std::string raw_name = x;
360- std::string result;
361- bool last_was_underscore = false;
362- for (const char& c : raw_name) {
363- if (isalnum(c)) {
364- result += tolower(c); // Add alphanumeric characters as lowercase
365- last_was_underscore = false;
366- } else if (!last_was_underscore) { // Replace non-alphanumeric with '_' but avoid consecutive '_'
367- result += '_';
368- last_was_underscore = true;
369- }
370- }
371- return result;
354+ return { esphome::tx_ultimate_easy::cached_device_name };
372355
373356tx_ultimate_easy :
374357 id : tx_ultimate
375358
376359wifi :
377360 id : wifi_component
361+ use_psram : true
362+
363+ on_connect :
364+ then :
365+ - lambda : |-
366+ tx_fw_version->publish_state("${version}");
367+ update_device_name->execute();
378368 ...
0 commit comments