Is name_add_mac_suffix not well-baked?

I’ve just started using this option (name_add_mac_suffix). It seems like a nice idea, but either I’m not using it correctly or it’s missing some finishing touches. I’m hoping it’s just me and that there is a simple answer.

If I set that option, the ESPHome dashboard always shows the device offline. I assume that’s because dashboard tries to resolve the name without a suffix and doesn’t find it. It looks like that option causes ESPHome to publish the suffixed name to mDNS.

A corollary to this is that OTA updates don’t work if the configuration uses DHCP addressing. However, even if I specify a static IP address (which gets OTA to work), dashboard still shows the device offline all the time.

I guess the recommendation is to use static addressing and to use the CLI instead of dashboard. Neither of those seem like the traditional newbie user friendliness of ESPHome. If one of the points of this config item is to enable sharing of configurations with others (a la the “Made for ESPHome” program), then it seems to call for a level of sophistication for those other users that isn’t completely desirable.

So, I’m hoping I’m wrong about this and have just missed some nice way to overcome these things. Have I?

1 Like

You might need to delete and re-add the device (under its new, longer name) to HA.

If HA formerly knew it as ‘my-light’ but it now calls itself ‘my-light-deadbeef’ (‘deadbeef’ is an example MAC address, yours will differ) then HA is never going to automatically recognize it as the device it formerly knew - it has a totally new name now.
No need to hardwire anything to the IP address, just delete it from the ESPHome integration and re-add it, and it’ll be fine.

I guess you are talking about the ESPHome add-on to HA. I’m talking about ESPHome by itself. The steps you describe could very well be true, but they’re not relevant AFAICT.

I don’t use the ESPHome addon to HA, so what I’m describing is relevant.

The ESP node’s name has been changed - by your adding the config item to extend it with the MAC - so HA can no longer ‘find’ the ESP under the name it formerly used.

Maybe I’m not getting what you are trying to tell me. Forget about HA for a minute. The thing I’m describing and asking about is the ESPHome dashboard. It is the thing that shows the device offline and is unable to do OTA updates. (I appreciate you trying to help, so if I’m still missing your point, please try again.)

You may be missing my point, then.
The ESP device has a name - you assign it in the YAML config.
The device advertises its existence on mDNS using that name.
And HA knows the device by its name (along with a few other attributes, I believe).

But,…
When you alter the YAML to include the MAC as part of the name, then the device’s name changes.
It now advertises its presence using its now-current name, which includes the MAC address as part of that name.

HA expects to find the device online using the name it had when first introduced to HA.
But the device has again arrived online but is now using a different name, so HA can no longer find it.
So HA accuses it of being ‘offline’, which is essentially correct, since no device using the original name is online.

You therefore need to convince HA to ‘forget’ the device it once knew, and then you need to introduce it to the device using its new name. Which is the basis of my original advice: Delete the original device from HA, and add the device back using its new name.

In alternative terms, the inclusion of the MAC suffix changes the hostname of your device (this is key).
So, it now looks like a totally different/new device as far as HA is concerned. The one it used to know is gone, never to return.

In different terms: If I call my device ‘frog’ and it goes online and advertises itself on mDNS as ‘frog’ I can find it using that name.
But if it later changes its name (which is what happens when you cause the MAC to be appended), I will no longer be able to find ‘frog’ using mDNS, because there’s no longer a device with that name.
I must now look for it using its new name: ‘frog-123456789ABC’ because that is its new and only name, due to appending the MAC address to its name.

I don’t know how else to explain this more clearly. I can only suggest that if you take my advice above, you will find success. If you disbelieve my advice, then I can only hope that you find some other way of understanding what has happened, and wish that you find success with it.

I got a little confused the first time I did the append mac workflow.

The docs don’t do much hand-holding.

I’m sure you’ll figure it out and then it will be easy;)

After you use the append mac option do you get a new device config with the mac appended?
image

After you see that pop-up, then you work with that one…

1 Like

After you use the append mac option do you get a new device config with the mac appended?

No, nothing like that happened for me. I just continued to have the original non-suffix entry in the dashboard. What you described sounds like a logical and useful way it should work, so maybe it’s just some local problem for me.

FWIW, I’m running the latest release (ESPHome version 2022.11.4) in a docker container. Maybe I’ll do some experiments and see if I can make it have this behavior.

What does your DHCP server believe the host is named?
And is it statically-reserved?

Hypothesis:

  1. Your router’s DNS is still finding the device under its prior name. (Since the node_name changed, it’s a good idea to make DNS match.)
  2. HA is confused, because while it can connect to the device using its old name, its conversation on the ESP-HA link provides a different name via the API, so HA ignores the device.

Suggestion:

  1. Delete the old-name’d integration, so HA has no more interest in it under that name.
  2. Ensure (by changing DHCP reservation, host files, whatever might be causing it to remain available using its old name) that the DNS name of the device matches its new actual ‘node_name’ (which will include the MAC).
  3. Re-add to HA the ESPHome device by supplying its new DNS hostname when the dialog asks for it.

That way, when the device contacts HA, its DNS name will lie up with what it calls itself within the ESP-HA conversation.

The name known to DNS has the suffix with an address assigned via DHCP. (I used the captive portal to configure the wifi creds after installing the firmware over USB.)

$ ping teatime-f56ed8.local
PING teatime-f56ed8.local (192.168.1.60) 56(84) bytes of data.
64 bytes from 192.168.1.60 (192.168.1.60): icmp_seq=1 ttl=255 time=122 ms
64 bytes from 192.168.1.60 (192.168.1.60): icmp_seq=2 ttl=255 time=143 ms

The names showing in the ESPHome dashboard continues to be without the suffix and continues to show the device offline. When I try to contact the device from the ESPHome dashboard, it tries to find it using the name without a suffix:

INFO Reading configuration /config/teatime.yaml...
INFO Starting log output from teatime.local using esphome API
WARNING Can't connect to ESPHome API for teatime.local: Error resolving IP address: [Errno -3] Temporary failure in name resolution
INFO Trying to reconnect to teatime.local in the background

If I add a use_address config with the suffixed name, the ESPHome dashboard can find it, but that sort of defeats the purpose of the option in the first place.

To make things concrete, here is the toy config file I’m working with, teatime.yaml. Maybe someone can spot some little thing I have wrong. I have a BMP280 sensor wired to an ESP32 just so there is some activity going on.

esphome:
  name: teatime
  name_add_mac_suffix: true

esp32:
  board: esp32dev

wifi:
  ap:
    ssid: "teatime Config AP"

captive_portal:
logger:
ota:
api:

i2c:
  - id: i_i2c
    sda: 'GPIO21'
    scl: 'GPIO22'

sensor:
  - platform: bmp280
    id: i_climate_sensor
    address: 0x76
    update_interval: 5s
    temperature:
      name: "teatime Temp"
      id: i_temp
      device_class: "temperature"
    pressure:
      name: "teatime AirPr"
      id: i_press
      device_class: "pressure"

@glyndon I appreciate you trying to help, but I still don’t understand why you continue to talk about HA. I’m asking about the ESPHome dashboard. Are you thinking that HA and the ESPHome dashboard are somehow talking to each other about devices on the network? I don’t think that’s true, but there’s a lot of clever stuff in ESPHome and HA.

Ah, I see. Thanks for reminding me of that. Yes, I had been of the assumption that you were linking the ESPs with HA. Hence, all my suggestions related to HA’s integration.

Since I’ve never used the ESPHome dashboard standalone, I’m unqualified to help with it, so will butt out.

this works for me:

esphome:
    name: espname
~~
wifi:
    ssid: !secret wifi_ssid
    password: !secret wifi_iotpw
    domain: internal.my
~~

where internal.my is the domain registered in my router.
I can address all my esp device’s with their dns:

espname.internal.my

@aceindy Do you use the name_add_mac_suffix option?

@wjcarpenter nope, only domain: :wink:

I just took a tour through ESPHome Dashboard.
It appears to populate itself using filenames and the contents of the .esphome/build directory.
I use a script to drive my builds, and it varies the node_name on several devices which all share a common YAML file.
When Dashboard displays those, it shows a card for only the last node_name that used a particular YAML file.
Since your node_name is generated at compile time and no longer matches the name of the YAML file, that node will always appear offline.

Now I see what you were asking about the feature possibly being half-baked, and I tend to agree. At least as far as Dashboard is concerned. Dashboard may need an overhaul to bring it into alignment with the mac_suffix feature.
Its node_discovery logic seems to have predated the addition of mac_suffix option, and so it’s failing to discover your new node, since it doesn’t appear to listen for them on the net.

What happens if you:

  1. Take a copy of your teatime.yaml into the same directory and rename it teatime-f56ed8.yaml
  2. Open it up and set
name: teatime-f56ed8.
  name_add_mac_suffix: false

Does it now show as online and use the config?
Can you OTA this config?

You should also probably set manual_ip: / static_ip.

Well, I don’t think I even need to try that to know that it would work. In fact, whether the file is renamed or not, ESPHome dashboard can find the device based on the name value. So, one could just modify the name value in the existing file after finding out what the MAC suffix would be for the device. That’s really no different that changing the name to something unrelated to the MAC. That does work.

When you got the renamed device to show up in ESPHome dashboard, as you posted earlier, was it because you modified the name in that YAML, or did it just show up without you needing to do anything about it?

I can’t recall tbh! Haven’t done the workflow that often.

It’s possible I do just do them manually. It’s also possible it automagically happens;)

Heh, fair enough, @Mahko_Mahko. Unless some new info comes to light, I’m just going to give up on this option for now and make unique names manually. Using this MAC business was just a sideline excursion anyhow.

1 Like