esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Incorrect addition of the last 3 bytes of the device MAC address to the device name #5167

Open ReliableBob opened 9 months ago

ReliableBob commented 9 months ago

The problem

When using the function of adding the last 3 bytes of the Mac address to the device name, an error occurs. The last 3 bytes of the MAC address are 71:05:2B, but the following is added to the device name: e1-710528 There is a clear mistake here. Instead of the symbol "B" the number "8" is used.

Of course, this causes the problem of accessing the device by host name.

Which version of ESPHome has the issue?

2023.11.6

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

nodemcu-32s

Component causing the issue

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 9 months ago

Can you paste logs?

ReliableBob commented 9 months ago
rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[I][logger:326]: Log initialized
[C][ota:473]: There have been 1 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[I][i2c.arduino:183]: Performing I2C bus recovery
[C][uart.arduino_esp32:077]: Setting up UART...
[C][pcf8574:010]: Setting up PCF8574...
[C][pcf8574:010]: Setting up PCF8574...
[D][number:012]: 'Long click delay': Sending state 1000.000000
[D][number:012]: 'Server IP 1': Sending state 0.000000
[D][number:012]: 'Server IP 2': Sending state 0.000000
[D][number:012]: 'Server IP 3': Sending state 0.000000
[D][number:012]: 'Server IP 4': Sending state 0.000000
[C][switch.gpio:011]: Setting up GPIO Switch 'LED Red'...
[D][switch:016]: 'LED Red' Turning OFF.
[D][switch:055]: 'LED Red': Sending state OFF
[D][switch:016]: 'LED Red' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'LED Green'...
[D][switch:016]: 'LED Green' Turning OFF.
[D][switch:055]: 'LED Green': Sending state OFF
[D][switch:016]: 'LED Green' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay 1'...
[D][switch:016]: 'Relay 1' Turning OFF.
[D][switch:055]: 'Relay 1': Sending state OFF
[D][switch:016]: 'Relay 1' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay 2'...
[D][switch:016]: 'Relay 2' Turning OFF.
[D][switch:055]: 'Relay 2': Sending state OFF
[D][switch:016]: 'Relay 2' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay 3'...
[D][switch:016]: 'Relay 3' Turning OFF.
[D][switch:055]: 'Relay 3': Sending state OFF
[D][switch:016]: 'Relay 3' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay 4'...
[D][switch:016]: 'Relay 4' Turning OFF.
[D][switch:055]: 'Relay 4': Sending state OFF
[D][switch:016]: 'Relay 4' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay 5'...
[D][switch:016]: 'Relay 5' Turning OFF.
[D][switch:055]: 'Relay 5': Sending state OFF
[D][switch:016]: 'Relay 5' Turning OFF.
[C][dallas.sensor:032]: Setting up DallasComponent...
[C][ethernet:029]: Setting up Ethernet...
[D][sensor:094]: 'uptm': Sending state 2.03400 s with 0 decimals of accuracy
[D][binary_sensor:034]: 'FN button': Sending initial state OFF
[D][binary_sensor:034]: 'Input 1': Sending initial state OFF
[D][binary_sensor:034]: 'Input 3': Sending initial state OFF
[D][binary_sensor:034]: 'Input 4': Sending initial state OFF
[D][binary_sensor:034]: 'Input 2': Sending initial state OFF
[D][binary_sensor:034]: 'Input 5': Sending initial state OFF
[D][binary_sensor:034]: 'Input 6': Sending initial state OFF
[I][ethernet:138]: Starting ethernet connection
[D][dallas.sensor:143]: 'Dallas Temperature': Got Temperature=24.4°C
[D][sensor:094]: 'Dallas Temperature': Sending state 24.37500 °C with 2 decimals of accuracy
[I][ethernet:149]: Connected via Ethernet!
[C][ethernet:354]:   IP Address: 192.168.90.226
[C][ethernet:355]:   Hostname: 'jethub-e1-710528'
[C][ethernet:356]:   Subnet: 255.255.255.0
[C][ethernet:357]:   Gateway: 192.168.90.1
[C][ethernet:362]:   DNS1: 192.168.90.1
[C][ethernet:363]:   DNS2: 77.88.8.8
[C][ethernet:383]:   MAC Address: 08:3A:F2:71:05:2B
[C][ethernet:388]:   Is Full Duplex: YES
[C][ethernet:393]:   Link Speed: 100
[C][web_server:123]: Setting up web server...
[C][ota:097]: Over-The-Air Updates:
[C][ota:098]:   Address: jethub-e1.local:3232
[C][mqtt:037]: Setting up MQTT...
[I][mqtt:234]: Connecting to MQTT...
[I][mqtt:274]: MQTT Connected!
[I][app:062]: setup() finished successfully!
[I][app:102]: ESPHome version 2023.11.6 compiled on Nov 30 2023, 09:18:51
[C][logger:416]: Logger:
[C][logger:417]:   Level: DEBUG
[C][logger:418]:   Log Baud Rate: 115200
[C][logger:420]:   Hardware UART: UART0
[C][logger:424]:   Level for 'component': NONE
[C][logger:424]:   Level for 'text_sensor': NONE
[C][logger:424]:   Level for 'uptm': NONE
[C][i2c.arduino:053]: I2C Bus:
[C][i2c.arduino:054]:   SDA Pin: GPIO5
[C][i2c.arduino:055]:   SCL Pin: GPIO4
[C][i2c.arduino:056]:   Frequency: 400000 Hz
[C][i2c.arduino:059]:   Recovery: bus successfully recovered
[I][i2c.arduino:069]: Results from i2c bus scan:
[I][i2c.arduino:075]: Found i2c device at address 0x20
[I][i2c.arduino:075]: Found i2c device at address 0x22
[I][i2c.arduino:075]: Found i2c device at address 0x51
[I][i2c.arduino:075]: Found i2c device at address 0x54
[I][i2c.arduino:075]: Found i2c device at address 0x56
[C][uart.arduino_esp32:124]: UART Bus 1:
[C][uart.arduino_esp32:125]:   TX Pin: GPIO33
[C][uart.arduino_esp32:126]:   RX Pin: GPIO34
[C][uart.arduino_esp32:128]:   RX Buffer Size: 256
[C][uart.arduino_esp32:130]:   Baud Rate: 115200 baud
[C][uart.arduino_esp32:131]:   Data Bits: 8
[C][uart.arduino_esp32:132]:   Parity: NONE
[C][uart.arduino_esp32:133]:   Stop bits: 1
[C][pcf8574:021]: PCF8574:
[C][pcf8574:022]:   Address: 0x20
[C][pcf8574:023]:   Is PCF8575: YES
[C][pcf8574:021]: PCF8574:
[C][pcf8574:022]:   Address: 0x22
[C][pcf8574:023]:   Is PCF8575: YES
[C][template.number:050]: Template Number 'Long click delay'
[C][template.number:050]:   Unit of Measurement: 'ms'
[C][template.number:051]:   Optimistic: YES
[C][template.number:052]:   Update Interval: 60.0s
[C][template.number:050]: Template Number 'Server IP 1'
[C][template.number:051]:   Optimistic: YES
[C][template.number:052]:   Update Interval: 60.0s
[C][template.number:050]: Template Number 'Server IP 2'
[C][template.number:051]:   Optimistic: YES
[C][template.number:052]:   Update Interval: 60.0s
[C][template.number:050]: Template Number 'Server IP 3'
[C][template.number:051]:   Optimistic: YES
[C][template.number:052]:   Update Interval: 60.0s
[C][template.number:050]: Template Number 'Server IP 4'
[C][template.number:051]:   Optimistic: YES
[C][template.number:052]:   Update Interval: 60.0s
[C][switch.gpio:068]: GPIO Switch 'LED Red'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 0 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'LED Green'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 1 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'Relay 1'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 8 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'Relay 2'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 9 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'Relay 3'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 10 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'Relay 4'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 11 via PCF8574
[C][switch.gpio:068]: GPIO Switch 'Relay 5'
[C][switch.gpio:091]:   Restore Mode: always OFF
[C][switch.gpio:031]:   Pin: 12 via PCF8574
[C][uptime.sensor:031]: Uptime Sensor 'uptm'
[C][uptime.sensor:031]:   Device Class: 'duration'
[C][uptime.sensor:031]:   State Class: 'total_increasing'
[C][uptime.sensor:031]:   Unit of Measurement: 's'
[C][uptime.sensor:031]:   Accuracy Decimals: 0
[C][uptime.sensor:031]:   Icon: 'mdi:timer-outline'
[C][template.text_sensor:020]: Template Sensor 'Controller uptime'
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'FN button'
[C][gpio.binary_sensor:016]:   Pin: GPIO0
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 1'
[C][gpio.binary_sensor:016]:   Pin: 0 via PCF8574
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 2'
[C][gpio.binary_sensor:016]:   Pin: 1 via PCF8574
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 3'
[C][gpio.binary_sensor:016]:   Pin: 2 via PCF8574
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 4'
[C][gpio.binary_sensor:016]:   Pin: 3 via PCF8574
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 5'
[C][gpio.binary_sensor:016]:   Pin: 4 via PCF8574
[C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Input 6'
[C][gpio.binary_sensor:016]:   Pin: 5 via PCF8574
[C][restart.button:017]: Restart Button 'Controller Restart'
[C][dallas.sensor:075]: DallasComponent:
[C][dallas.sensor:076]:   Pin: GPIO16
[C][dallas.sensor:077]:   Update Interval: 60.0s
[D][dallas.sensor:082]:   Found sensors:
[D][dallas.sensor:084]:     0x123c01a8163b6028
[C][dallas.sensor:089]:   Device 'Dallas Temperature'
[C][dallas.sensor:089]:     Device Class: 'temperature'
[C][dallas.sensor:089]:     State Class: 'measurement'
[C][dallas.sensor:089]:     Unit of Measurement: '°C'
[C][dallas.sensor:089]:     Accuracy Decimals: 2
[C][dallas.sensor:091]:     Index 0
[C][dallas.sensor:097]:     Address: 0x123c01a8163b6028
[C][dallas.sensor:098]:     Resolution: 12
[C][ethernet:222]: Ethernet:
[C][ethernet:354]:   IP Address: 192.168.90.226
[C][ethernet:355]:   Hostname: 'jethub-e1-710528'
[C][ethernet:356]:   Subnet: 255.255.255.0
[C][ethernet:357]:   Gateway: 192.168.90.1
[C][ethernet:362]:   DNS1: 192.168.90.1
[C][ethernet:363]:   DNS2: 77.88.8.8
[C][ethernet:383]:   MAC Address: 08:3A:F2:71:05:2B
[C][ethernet:388]:   Is Full Duplex: YES
[C][ethernet:393]:   Link Speed: 100
[C][ethernet:227]:   MDC Pin: 23
[C][ethernet:228]:   MDIO Pin: 18
[C][ethernet:229]:   Type: LAN8720
[C][ethernet:230]:   PHY addr: 1
[C][ethernet_info:011]: EthernetInfo IPAddress 'Controller IP'
[C][web_server:168]: Web Server:
[C][web_server:169]:   Address: jethub-e1.local:80
[C][mdns:115]: mDNS:
[C][mdns:116]:   Hostname: jethub-e1-710528
[C][ota:097]: Over-The-Air Updates:
[C][ota:098]:   Address: jethub-e1.local:3232
[C][mqtt:133]: MQTT:
[C][mqtt:135]:   Server Address: 10.200.1.1:1883 (10.200.1.1)
[C][mqtt:136]:   Username: 'pressen'[redacted]
[C][mqtt:137]:   Client ID: 'jethub-e1-710528-083af2710528'[redacted]
[C][mqtt:142]:   Topic Prefix: 'jethub-e1'
[C][mqtt:144]:   Log Topic: 'jethub-e1/log'
[C][mqtt:147]:   Availability: 'jethub-e1/status'
[C][http_request:014]: HTTP Request:
[C][http_request:015]:   Timeout: 10000ms
[C][http_request:016]:   User-Agent: esphome/device
[C][http_request:017]:   Follow Redirects: 1
[C][http_request:018]:   Redirect limit: 3
[C][mqtt.button:029]: MQTT Button 'Controller Restart': 
[C][mqtt.button:030]:   State Topic: 'jethub-e1/button/controller_restart/state'
[C][mqtt.button:030]:   Command Topic: 'jethub-e1/button/controller_restart/command'
[C][mqtt.switch:041]: MQTT Switch 'LED Red': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/led_red/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/led_red/command'
[C][mqtt.switch:041]: MQTT Switch 'LED Green': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/led_green/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/led_green/command'
[C][mqtt.switch:041]: MQTT Switch 'Relay 1': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/relay_1/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/relay_1/command'
[C][mqtt.switch:041]: MQTT Switch 'Relay 2': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/relay_2/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/relay_2/command'
[C][mqtt.switch:041]: MQTT Switch 'Relay 3': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/relay_3/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/relay_3/command'
[C][mqtt.switch:041]: MQTT Switch 'Relay 4': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/relay_4/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/relay_4/command'
[C][mqtt.switch:041]: MQTT Switch 'Relay 5': 
[C][mqtt.switch:042]:   State Topic: 'jethub-e1/switch/relay_5/state'
[C][mqtt.switch:042]:   Command Topic: 'jethub-e1/switch/relay_5/command'
[C][mqtt.sensor:028]: MQTT Sensor 'Dallas Temperature':
[C][mqtt.sensor:032]:   State Topic: 'jethub-e1/sensor/dallas_temperature/state'
[C][mqtt.text_sensor:023]: MQTT Text Sensor 'Controller IP':
[C][mqtt.text_sensor:024]:   State Topic: 'jethub-e1/sensor/controller_ip/state'
[C][mqtt.text_sensor:023]: MQTT Text Sensor 'Controller uptime':
[C][mqtt.text_sensor:024]:   State Topic: 'jethub-e1/sensor/controller_uptime/state'
[C][mqtt.number:033]: MQTT Number 'Long click delay':
[C][mqtt.number:034]:   State Topic: 'jethub-e1/number/long_click_delay/state'
[C][mqtt.number:033]: MQTT Number 'Server IP 1':
[C][mqtt.number:034]:   State Topic: 'jethub-e1/number/server_ip_1/state'
[C][mqtt.number:033]: MQTT Number 'Server IP 2':
[C][mqtt.number:034]:   State Topic: 'jethub-e1/number/server_ip_2/state'
[C][mqtt.number:033]: MQTT Number 'Server IP 3':
[C][mqtt.number:034]:   State Topic: 'jethub-e1/number/server_ip_3/state'
[C][mqtt.number:033]: MQTT Number 'Server IP 4':
[C][mqtt.number:034]:   State Topic: 'jethub-e1/number/server_ip_4/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'FN button':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/fn_button/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 1':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_1/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 2':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_2/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 3':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_3/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 4':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_4/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 5':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_5/state'
[C][mqtt.binary_sensor:022]: MQTT Binary Sensor 'Input 6':
[C][mqtt.binary_sensor:023]:   State Topic: 'jethub-e1/binary_sensor/input_6/state'
ssieb commented 9 months ago

Paste your config.

ReliableBob commented 9 months ago
substitutions:
  devicename: "jethub-e1"
  device_description: "JetHub E1 controller"
  ip: 10.200.1.12
  gateway: 10.200.1.254
esphome:
  name: $devicename
  comment: "${device_description}"
  platform: ESP32
  board: nodemcu-32s
  name_add_mac_suffix: true # This option adds MAC address to the end of the device name

## WARNING: Disable WiFi and captive_portal if Ethernet enabled
#wifi:
#  ssid: "***"
#  password: "***"
#
#  # Enable fallback hotspot (captive portal) in case wifi connection fails
#  ap:
#    ssid: "JetHub E1 Fallback Hotspot"
#    password: "***"
#
#captive_portal:

# Enable Ethernet
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 1
  # manual_ip:
  #   static_ip: $ip
  #   gateway: $gateway
  #   subnet: 255.255.255.0
# Enable logging
logger:
  logs:
    component: NONE
    text_sensor: NONE
    uptm: NONE
# Enable Home Assistant API
# api:
#   encryption:
#     key: "HiCfFdPxgUv4Lgp3ijVyRPG79NG8ckRudFGqVIYuqvg="

# Enable OTA firmware update
ota:

http_request:
  useragent: esphome/device
  timeout: 10s

mqtt:
  broker: 10.200.1.1
  username: pressen
  password: !secret mqtt_testst_password
  # client_id: $devicename
  discovery: false
  topic_prefix: $devicename
  log_topic: ${devicename}/log

web_server:
  port: 80
  version: 2
  include_internal: false
  ota: true
  # log: false
  #local: true

# Enable I2C bus
i2c:
  sda: 5
  scl: 4
  frequency: 400kHz
  scan: true
  id: i2c1

# Enable UART1
uart:
  - tx_pin: 33
    rx_pin: 34
    baud_rate: 115200
    id: uart_1

# Enable I2C GPIO expanders
pcf8574:
  - id: cpu_gpio_exp
    address: 0x20
    pcf8575: true
  - id: mb_gpio_exp
    address: 0x22
    pcf8575: true
ssieb commented 9 months ago

Ok, I'm pretty sure that the mac address that is used is the wifi one. It's just an identifier, so that makes sense.

bartowl commented 6 months ago

Yep, looks like it uses always wifi mac, regardless whether it connects via ethernet or wifi. I have this issue too, and it is a silly problem with mikrotik integration which cannot associate presence sensor with this device via MAC association... Would be great id there was a way to use ethernet MAC as identifier...

randybb commented 2 days ago

So by default esp_read_mac() is just base MAC of ESP. Ethernet MAC = base_mac +3 to the last octet

https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/misc_system_api.html#mac-address

probot-esphome[bot] commented 2 days ago

Hey there @gtjadsonsantos, mind taking a look at this issue as it has been labeled with an integration (ethernet_info) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

victorclaessen commented 1 day ago

So on ESP32, it looks like the Ethernet Info Text Sensor gets the MAC like this:

For the ethernet MAC address, the expressif function esp_read_mac can be called, with argument ESP_MAC_ETH.

It's not complicated, but unfortunately, I don't really know how the maintainers of this component would like to handle this. My suggestion is to add a type parameter to get_mac_address_raw, and then return the ethernet MAC if that's requested by the parameter value. It could even be extended to return the softAP MAC and bluetooth MAC, depending on the parameter value (and if those MACs are available on the specific platform).