Mystery sensors? Where did these come from?

Flashed a new ESPHome device, but in Developer Tools > States I am getting some sensor entities that just shouldn’t exist.

All of the “sensor.esp_switch_” should be “freds-chair_”

When creating a card from the configuration, the card looks OK, until you look at the YAML code:

Now, the YAML code:

Any guesses WTF is going on?

Here is the YAML code that created the entities:

substitutions:
  device_name: freds-chair
  friendly_name: freds_chair

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #fast_connect: true
    
    
sensor:
  - platform: uptime
    name: ${friendly_name} Uptime
    filters:
      - lambda: return x / 3600.0 /24;
    unit_of_measurement: "days"
    accuracy_decimals: 0

  - platform: wifi_signal
    name: ${friendly_name} WiFi Level
    id: ${friendly_name}_WiFi_level
    update_interval: 300s

# Get the WiFi details
text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP
    ssid:
      name: ${friendly_name} SSID
    mac_address:
      name: ${friendly_name} Mac Address    
    

Yes. Digging deep in my memory banks I seem to remember you can’t use underscore. Try your Friendly Name as a friendly name!

Freds Chair

Edit: also I gave up on Substitutions because by using Friendly Name the Friendly Name is automatically added after sensor.

Edit 2: I am sure someone will explain better or correctly!

You don’t need substitutions for friendly name any more

If you have this (or similar) in your config:

esphome:
  name: air-filter
  friendly_name: Air Purifier
  comment: ESP32 DEV BOARD

then esphome will now name all your entities NAME entity, ie:

fan:
  - platform: speed
    output: fan_output
    name: Fan
    speed_count: 10

will create entity Air Purifier Fan, fan.air_purifier_fan

Also, If you have a friendly_name set for your device and you want the entity to use that name, you can set name: None. This would create a fan entity called Air Purifier

Thanks.
That doesn’t explain where the strange sensor names came from, or how to fix them.

No, sorry was replying to @JulianDH’s post about friendly names

This is serving up that sensor you highlighted in your screenshot.

This is not the complete YAML of that device. Where are the board codes and all that?

The name that will be used by ESPHome for that device comes from the name entity under the esphome: entry.

The documentation says this:

Here you specify some core information that ESPHome needs to create firmwares. Most importantly, this is the section of the configuration where you specify the name of the node.

So for your case, you’d need to set the config entries, if you don’t want ESPHome to name your device. And that is what’s happening here: you didn’t specify a name for that device. Not the device_name, not the friendly_name, just the name for your device. If this isn’t set, ESPHome does generate a name.

This

substitutions:
  device_name: freds-chair
  friendly_name: freds_chair

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #fast_connect: true

needs this to be correct and the naming will be like you want it:

substitutions:
  device_name: freds-chair
  friendly_name: freds_chair

esphome:
  name: freds_chair #or whatever you name it

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #fast_connect: true

To get there, I’d suggest copying the YAML from that device, delete it in ESPHome and HA-ESP-integration and set it up new in ESPHome, where you can re-add the YAML code and add the name.

Btw. I’m surprised this is working. Normally you need to define the board for ESPHome to generate a firmware…?

1 Like

Fair question.
Since I am almost always using an ESP8266 device with a lot of the same code at the top of the device file, I have moved the repetitive stuff to packages (common files). It makes my device files smaller.

Yes, there is a name: component in one of the common files.

esphome:
  name: ${device_name}

Below are the whole device YAML file, and the common files.

# This is the chair servo for the 2023 Halloween props.

# PWM Output is on GPIO2
# A button can be added to GPIO0

substitutions:
  device_name: freds-chair
  friendly_name: freds_chair

packages:
  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml

######################################################

output:
  - platform: esp8266_pwm
    id: pwm_output
    pin: 2
    frequency: 50 Hz

servo:
  - id: servo_signal
    output: pwm_output
    restore: true

number:
  - platform: template
    name: ${friendly_name} servo control
    min_value: -100
    max_value: 100
    step: 1
    set_action:
      then:
        - servo.write:
            id: servo_signal
            level: !lambda 'return x / 100.0;'
            
button:
  - platform: template
    name: ${friendly_name} zero
    icon: "mdi:liquid-spot"
    on_press:
      then:
        - script.execute: move_to_zero

  - platform: template
    name: ${friendly_name} look left
    icon: "mdi:liquid-spot"
    on_press:
      then:
        - script.execute: look_left

  - platform: template
    name: ${friendly_name} look right
    icon: "mdi:liquid-spot"
    on_press:
      then:
        - script.execute: look_right



#Pressing the button on GPIO0 returns the servo to zero.
#binary_sensor:
#  - platform: gpio
#    name: ${friendly_name} action_button
#    pin:
#      number: 0
#      mode: input_pullup
#      inverted: True
#    id: button_fire
#    on_press:
#      then:
#        - script.execute: move_to_zero
    

script:
  - id: move_to_zero
    then:
      - servo.write:
          id: servo_signal
          level: 0%

  - id: look_left
    then:
      - servo.write:
          id: servo_signal
          level: 100%

  - id: look_right
    then:
      - servo.write:
          id: servo_signal
          level: -100%

esp8266.yaml common file:

################################################
#esp8266
#
#Useage:
#packages:
#  wifi: !include common/wifi.yaml
#  device_base: !include common/esp8266.yaml
#
#In the project file, you can override the default board type.
#For example:
#esp8266:
#  board: esp01_1m    #Sonoff Basic and Mini (DEFAULT)
#  board: d1_mini     #Wemos D1 Mini
#  board: nodemcuv2   #NodeMCU
#
################################################

esphome:
  name: ${device_name}

esp8266:
  board: esp01_1m
  framework:
    version: recommended
    
# Logger level "debug" is needed to get 1-Wire addresses, like the ds18b20.
logger:
  level: DEBUG

api:

ota:
  safe_mode: True

wifi.yaml Common File

# Connect to Kaywinnet
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #fast_connect: true
    
    
sensor:
  - platform: uptime
    name: ${friendly_name} Uptime
    filters:
      - lambda: return x / 3600.0 /24;
    unit_of_measurement: "days"
    accuracy_decimals: 0

  - platform: wifi_signal
    name: ${friendly_name} WiFi Level
    id: ${friendly_name}_WiFi_level
    update_interval: 300s

# Get the WiFi details
text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP
    ssid:
      name: ${friendly_name} SSID
    mac_address:
      name: ${friendly_name} Mac Address    

web_server:
  port: 80       

I know where sensors come from. The problem is
friendly_name: freds_chair.
Where is “esp_switch” coming from?

As Paddy said, you did not include a name so ESPHome added one for you.

Yes, I did; I always do. See post #8
My apologies for not posting all the YAML code.

So why did you ask?

Why did I ask what?

The friendly name is:
friendly_name: freds_chair.
Where is “esp_switch” coming from?

You provided the ID and the FRIENDLY NAME, you did not provide the entity_id that is passed to HA, therefore it picked up the defaults for the entity ID, but your friendly names appear to be as you would expect. The ID you supplied is the ESPHome reference ID that you can use in other code.

I believe I said that correctly, @tom_l please correct me if I did not represent the issue and solution properly.

For the third time, you did not include a name: so ESPHome added a default name for you.

In general, is it safe to delete all files and folders for a device that no longer exists? (Asked before in Can I delete these files? - ESPHome - Home Assistant Community (home-assistant.io))

Yes I did:

esphome:
  name: ${device_name}

HA uses the “name” from esphome to create the entity ID.

esphome:
  name: ${device_name}

I’ve been using these packages on more than a dozen devices and never had a name issue.

But back to the earlier question- can I safely delete the device from the ESPHome control panel then delete all of the freds-chair.* files and start over?

That’s unfortunate, I had hoped it might be just that. :wink:

What you’re doing should in theory work… And I assume you already checked, that both “package” files are available? Sorry, but I have no idea what could be the reason.

You should enable the debug logs in ESPHome for the device and run an install. Maybe that brings some insight. I would speculate, that if there is some “misconfiguration” with the name, eg. something with the 8266.yaml file is wrong, that ESPHome just logs a warning and generates the name. Worth a try to check these logs.

That brings us to your next question. Yes, it is safe to delete the files. I read your other topic, and would as well delete the freds-chair files. Just start fresh, and don’t forget to delete all entities upfront in HA! Maybe try to use “fresh” naming like fredschair without a hyphen or something like that. :slight_smile:

Good luck, let us know the outcome! :slight_smile: