ESP32 network name with added mac suffix

If you plan same code with many ESP32’s to work same house you can use ths code, it displays real network name, with same as captive portal name

substitutions:
  name: "smart-display" # MODIFY THIS VALUE
  friendly_name: Smart Display
  comment: "${friendly_name} Devleoping Version"  # MODIFY THIS VALUE

esphome:
  name: "${name}"
  name_add_mac_suffix: true # this makes esp32's name to like 'smart-display-e8d3b6.local'
  friendly_name: "${friendly_name}"
  comment: "${comment}"  

globals:
  - id: mdns_name
    type: std::string
    restore_value: yes
    max_restore_data_length: 31
    initial_value: '"${name}"'

esp32:
  board: esp32-c6-devkitc-1
  framework:
    type: esp-idf

wifi:
  ap:

captive_portal:

text_sensor:

  - platform: wifi_info
    mac_address: # this is esp32's wifi network macID, it's unique
      entity_category: diagnostic
      name: "WiFi MacID"
      icon: mdi:ip-network
      id: wifi_macid
      internal: True # we don't display macID in web page, if you wish turn False

  - platform: template  # this is ESP32's web interface address
    name: "Web Interface address"  
    id: esphome_wifi_url
    icon: mdi:information-variant-circle-outline
    entity_category: diagnostic
    update_interval: 1hours
    lambda: !lambda |-
              std::string strArray[20] = { id( wifi_macid ).state};
              std::string adres="http://" + id(mdns_name) + "-" ;
              std::string kod ="";
              for ( std::string s : strArray ) {
                  kod = kod + s.c_str();
              }
              std::string son3 = kod.substr(9,2);  
              std::string son2 = kod.substr(12, 2);
              std::string son1 = kod.substr(15, 2);
              for (char &c : son1 ) {
                      if (c >= 'A' && c <= 'Z') {
                          c += 32;
                      }
                  }
              for (char &c : son2 ) {
                      if (c >= 'A' && c <= 'Z') {
                          c += 32;
                      }
                  }
              for (char &c : son3 ) {
                      if (c >= 'A' && c <= 'Z') {
                          c += 32;
                      }
                  }                  
              ESP_LOGI("web: ", "You can browse this ESP with  %s address.", (adres +  son3 + son2 + son1 + ".local/").c_str());
              return {adres +  son3 + son2 + son1 + ".local/"};
    
2 Likes