Ouch! ESPHome update + device updates = Athom device new entity/attributes, generically renamed(!)

Saw the update for ESPHome 2023.3.1, so I went ahead and updated it. Then all of my ESPHome devices showed up as having updates, so I updated them via Update All. However, now my Sankey Energy chart, and for that matter, any chart, graph, or statistic that included Anthom smart plug energy data is broken. And my energy trend statistics are now thrown off for these devices. The Kauf plugs fortunately retained their entity and attribute names.

For example, sensor.refrigerator_energy is now sensor.energy_3, and so forth.

Every entity and attribute in the Athom smart plugs’ metadata is now plainly named, instead of having the device name for the entity name and prepended for the attributes.

I didn’t change any of the yaml for the Anthom smart plugs, here’s the refrigerator yaml as an example;

substitutions:
  name: refrigerator
  friendly_name: Refrigerator
packages:
  athom.smart-plug-v2: github://athom-tech/athom-configs/athom-smart-plug-v2.yaml
esphome:
  name: ${name}
  name_add_mac_suffix: false
api:
  encryption:
    key: CfY4Ms3irbUlrM0gtYTwpHC8d/Yx890tsmeSBvt79/g=

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.50.5

The logs from the device updates didn’t throw what I thought were suspicious errors. Here’s a tiny portion from the end of the compile/build from the Clothes Dryer Athom plug update;

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.50.47 using esphome API
WARNING Can't connect to ESPHome API for 192.168.50.47: Timeout while connecting to ('192.168.50.47', 6053)
INFO Trying to reconnect to 192.168.50.47 in the background
INFO Successfully connected to 192.168.50.47
[20:33:17][W][api.connection:071]: 192.168.50.83: Socket operation failed: BAD_INDICATOR errno=11
[20:33:17][I][app:102]: ESPHome version 2023.2.3 compiled on Feb 21 2023, 20:30:10
[20:33:17][I][app:104]: Project athom.smart-plug-v2 version 1.1

and it appears that attributes like Clothes Dryer Total Daily Energy should have been set, for example;

[20:33:18][D][sensor:126]: 'Clothes Dryer Total Daily Energy': Sending state 0.00000 kWh with 3 decimals of accuracy
[20:33:18][D][api:102]: Accepted 192.168.50.83
[20:33:18][W][api.connection:071]: 192.168.50.83: Socket operation failed: BAD_INDICATOR errno=11

The only fly in the ointment may have been the socket operation failure, though the data itself has been sent to the new generic attribute.

Clearly, I did something wrong, but I have been unable to find anything in the prior posts that point to this issue.

Questions;

  1. What did I do wrong?

  2. What is the correct procedure for updating Athom devices without overwriting their attribute names, so that this doesn’t happen over and over again?

  3. Is there any way to recapture the energy data for these devices?

Same issue here. Any suggestions other than rolling back EspHome?

I expect you had a version prior 2023.02 running? :thinking:

And also didn’t read the breaking changes? :grimacing:

If you not a fan of reading change logs or release notes the minimum one needs (should) care about is the breaking changes - that’s not only true for esphome but also for home assistant and other stuff which might be mission critical or a pita when going south :arrow_lower_right:

So for the future better save then sorry to avoid any foreseeable ouches! :joy:

Changelog âž” ESPHome 2023.2.0 - 15th February 2023

Friendly Name

ESPHome now supports setting a friendly_name which is sent to Home Assistant. This name will be used for the config entry, the device name, and will be automatically prefixed to all of the entities where needed by Home Assistant.

Note:

If you opt to use this new friendly name, take note that you should remove any friendly name (substitition) that you currently prepend onto entity name in YAML.

1 Like

Ah, didn’t read all the way to the end, they start becoming a blur after awhile. I’ll have to carefully read how to set a friendly_name in ESPHome. Thanks @orange-assistant !

Finding specific threads on this topic reveals that HA will create new entities, and abandon the prior entities created with substitutions, so it appears I’ll have to start my energy data capture on these items all over again, which hobbles my energy tracking to a degree. Sigh…

Ok, so I read a thread on the change to make, and I eliminated substitutions altogether, with the following .yaml file;

esphome:
  name: clothes-dryer
  friendly_name: Clothes Dryer
  name_add_mac_suffix: false
packages:
  athom.smart-plug-v2: github://athom-tech/athom-configs/athom-smart-plug-v2.yaml
api:
  encryption:
    key: 9Oq0tr53+OD3hUHNqjIr/U/PqVRjxabYwl/Sk5XOJhg=

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.50.47

Unfortunately, that didn’t work. So I took a look at the Athom gitub package that is pulled in with their default yaml and which had just been updated 6 hours prior(!), and low and behold it included the following;

substitutions:
  device_name: "athom-smart-plug-v2"
  friendly_name: "Athom Smart Plug V2"
  project_name: "athom.smart-plug-v2"
  project_version: "1.1"
  relay_restore_mode: RESTORE_DEFAULT_OFF

esphome:
  name: "${device_name}"
  name_add_mac_suffix: true
  project:
    name: "${project_name}"
    version: "${project_version}"

So following the fine example set by @Cuddon , I copied out all of the rest of the Athom github yaml to insert directly into the HA clothes dryer yaml file (removing extraneous api and wifi lines that are already in use in the existing file). I changed the ESPHome friendly_name to “ClothesDryer” to distinguish it from the prior “Clothes Dryer” in case there were any name conflicts or collisions, and commented out the dashboard_import line because all it did was refer to the github yaml file that has the accursed substitutions;

esphome:
  name: clothes-dryer
  friendly_name: ClothesDryer
  name_add_mac_suffix: true

esp8266:
  board: esp8285
  restore_from_flash: true

preferences:
  flash_write_interval: 1min
  
ota:

logger:
  baud_rate: 0

mdns:
  disabled: false

web_server:
  port: 80

#wifi:
#  ap: {} # This spawns an AP with the device name and mac address with no password.

captive_portal:

#dashboard_import:
#  package_import_url: github://athom-tech/athom-configs/athom-smart-plug-v2.yaml

uart:
  rx_pin: RX
  baud_rate: 4800

globals:
  - id: total_energy
    type: float
    restore_value: yes
    initial_value: '0.0' 

binary_sensor:
  - platform: status
    name: "${friendly_name} Status"

  - platform: gpio
    pin:
      number: 5
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Power Button"
    disabled_by_default: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: relay
      - timing:
          - ON for at least 4s
        then:
          - button.press: Reset

sensor:
  - platform: uptime
    name: "${friendly_name} Uptime Sensor"

  - platform: cse7766
    update_interval: 10s
    current:
      name: "${friendly_name} Current"
      filters:
          - lambda: if (x < 0.060) return 0.0; else return x;   #For the chip will report less than 3w power when no load is connected


    voltage:
      name: "${friendly_name} Voltage"
    power:
      name: "${friendly_name} Power"
      id: power_sensor
      filters:
          - lambda: if (x < 3.0) return 0.0; else return x;    #For the chip will report less than 3w power when no load is connected


    energy:
      name: "${friendly_name} Energy"
      id: energy
      unit_of_measurement: kWh
      filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
      on_value:
        then:
          - lambda: |-
              static float previous_energy_value = 0.0;
              float current_energy_value = id(energy).state;
              id(total_energy) += current_energy_value - previous_energy_value;
              previous_energy_value = current_energy_value;
  - platform: template
    name: "${friendly_name} Total Energy"
    unit_of_measurement: kWh
    device_class: "energy"
    state_class: "total_increasing"
    icon: "mdi:lightning-bolt"
    accuracy_decimals: 3
    lambda: |-
      return id(total_energy);
    update_interval: 10s

  - platform: total_daily_energy
    name: "${friendly_name} Total Daily Energy"
    restore: true
    power_id: power_sensor
    unit_of_measurement: kWh
    accuracy_decimals: 3
    filters:
      - multiply: 0.001


button:
  - platform: factory_reset
    name: "Restart with Factory Default Settings"
    id: Reset
    
  - platform: safe_mode
    name: "Safe Mode"
    internal: false

switch:
  - platform: gpio
    name: "${friendly_name}"
    pin: GPIO12
    id: relay
    restore_mode: ${relay_restore_mode}

light:
  - platform: status_led
    name: "${friendly_name} Status LED"
    id: blue_led
    disabled_by_default: true
    pin:
      inverted: true
      number: GPIO13

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "IP Address"
    ssid:
      name: "Connected SSID"
    mac_address:
      name: "Mac Address"
     
time:
  - platform: sntp
    id: sntp_time
api:
  encryption:
    key: 9Oq0tr53+OD3hUHNqjIr/U/PqVRjxabYwl/Sk5XOJhg=

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.50.47

This did reset each of the attributes, and is collecting power/energy data, though the attribute renaming is not coming through;

I feel I’m close but there is something else I need to do to have the attribute names prepended with the ESPHome friendly_name. Any ideas?

How are you going with this? I have the same problem, with now 27 entities for each of my Athom plugs. I also use them for energy tracking on major appliances. I’m a bit unsure how to proceed here; I am using the stock ESPHome configuration settings and haven’t included the friendly name syntax yet. My entities are now a mess!

I have made no headway with this since my last update, may have to consider the Athom smartplugs as worthless.

Hello I also have been using the Athom yaml configuration from GitHub. I updated a few months ago to the new version. It all seems to be working well BUT I have not changed the “friendly name” from the first version. So have not experienced the same problem.

If you are not seeing the names coming through, standard procedure is to delete the ESP Node from the ESPHome integration and then re- integrate. You can check the logs in the ESPHome dashboard to see that the node is reporting the correct naming you specified. Good luck

1 Like