Cant see correct Entity Name on Home Assistant

I am facing an issue with one of the switches on HA config. While it was working all right , since a few days the name of the switch I see in the entities is different from the one I have configures in the yaml file. Details below:
Config in configuration.yaml:
switch: !include switches.yaml

And the following entry in switches.yaml

  - platform: mqtt
    name: "Parking Light"
    state_topic: "home/parking/RESULT"
    value_template: '{{ value_json["POWER"] }}'
    command_topic: "home/parking/cmnd/POWER"
    availability_topic: "home/parking/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

What I see in the entities filter:
switch.parking_light_2

At times when I restart HA, the correct entity comes back as parking_light but mostly it is the wrong one with _2 appended.
Can anybody help?

You have this in config under “switch”
OR
You have included and this is in switch.yaml

Can’t just be in config by itself

yes, you’re right. I have included the file switches.yaml in my configuration.yaml as below
switch: !include switches.yaml

What type of switch is this?

It looks like it may have been auto discovered as well as being defined by your manual config.

Check configuration / integration / mqtt devices.

Also use an mqtt client like mqttExplorer or mqttfx to check the mqtt server for retained messages relating to the discovery of this device. The topic to check will be something like:

homeassistant/switch/#

Hi Tom,
Thanks for the suggestion. I did have discovery on in the config. When I turned it off and restarted HA, I had another switch that went into the same state as this. Now I have another switch is names as Temple Light but is showing up as temple_light_2. And well, the parking light remains the same.
I looked at the MQTT messages too, I dont see anything amiss there. screenshot attached.
Also pasted my entire configuration.yaml and switches.yaml for clarity. Any more help?
I am using Tasmota on all of these devices.
Also, I checked the MQTT integration devices , it does not show any devices there.

Full Configuration.yaml:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: xxxx
  longitude: xxxx
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 884
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Asia/Kolkata
  # Customization file
  customize: !include customize.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

#configure iOS app to be used
ios:

#include this file for themes, Source: https://github.com/arsaboo/homeassistant-config/blob/e082c33594fc497d60d3ea8c765e025fe0cc092d/frontend.yaml
frontend: !include frontend.yaml

# Enables configuration UI
config:
  

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
#http:
  # Secrets are defined in the file secrets.yaml
  #api_password: !secret http_password

#discovery:

# Text to speech
tts:
  - platform: google_translate
    service_name: google_say

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
sensor: !include sensor.yaml
switch: !include switches.yaml
binary_sensor: !include binary_sensor.yaml


#delete boolean.yaml after validating as I dont need this anymore
#input_boolean: !include boolean.yaml

Full switches.yaml:

#switch:
  - name: Study Fan
    platform: mqtt
    state_topic: home/study/relay/0
    command_topic: home/study/relay/0/set
    payload_on: 1
    payload_off: 0
    availability_topic: home/study/status
    payload_available: 1
    payload_not_available: 0

  - name: Study Light
    platform: mqtt
    state_topic: home/study/relay/1
    command_topic: home/study/relay/1/set
    payload_on: 1
    payload_off: 0
    availability_topic: home/study/status
    payload_available: 1
    payload_not_available: 0

  - platform: mqtt
    name: "MBR Fan"
    state_topic: "home/mbr/RESULT"
    value_template: '{{ value_json["POWER1"] }}'
    command_topic: "home/mbr/cmnd/POWER1"
    availability_topic: "home/mbr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "MBR Light"
    state_topic: "home/mbr/RESULT"
    value_template: '{{ value_json["POWER2"] }}'
    command_topic: "home/mbr/cmnd/POWER2"
    availability_topic: "home/mbr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "KBR Light"
    state_topic: "home/kbr/RESULT"
    value_template: '{{ value_json["POWER1"] }}'
    command_topic: "home/kbr/cmnd/POWER1"
    availability_topic: "home/kbr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "KBR Fan"
    state_topic: "home/kbr/RESULT"
    value_template: '{{ value_json["POWER2"] }}'
    command_topic: "home/kbr/cmnd/POWER2"
    availability_topic: "home/kbr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "Parking Light"
    state_topic: "home/parking/RESULT"
    value_template: '{{ value_json["POWER"] }}'
    command_topic: "home/parking/cmnd/POWER"
    availability_topic: "home/parking/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "Temple Light"
    state_topic: "home/temple/RESULT"
    value_template: '{{ value_json["POWER"] }}'
    command_topic: "home/temple/cmnd/POWER"
    availability_topic: "home/temple/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "Security Siren"
    state_topic: "home/security/siren/RESULT"
    value_template: '{{ value_json["POWER"] }}'
    command_topic: "home/security/siren/cmnd/POWER"
    availability_topic: "home/security/siren/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "FMR Light"
    state_topic: "home/fmr/RESULT"
    value_template: '{{ value_json["POWER1"] }}'
    command_topic: "home/fmr/cmnd/POWER1"
    availability_topic: "home/fmr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "FMR Fan"
    state_topic: "home/fmr/RESULT"
    value_template: '{{ value_json["POWER2"] }}'
    command_topic: "home/fmr/cmnd/POWER2"
    availability_topic: "home/fmr/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false


You have to decide if you want to stick with auto discovery of mqtt devices or manually enter them.

Auto:
Delete your manual configurations for discovered devices and put discovery: back in the config.


Manual:
Put discovery: back in the config. It might come in handy later.

Turn off discovery in your devices, not home assistant.

You did not answer my question about the switch type but it looks like a sonoff. If so, SetOption19 = 0 in the device’s console web interface will disable discovery for sonoff’s flashed with Tasmota.

You may have auto discovered entities that need to be deleted. Check configuration / entity registry.

Do not delete the mqtt integration.

Also in future you might want to sanitise your configuration before posting it. Particularly the lat and lon.

Maybe post entire switch.yaml?

Did you verify

@tmjpugh I posted my entire switches.yaml above

Hi @tom_l , Yes these are SONOFFs with Tasmota flashed on them.
I did as you suggested:
SetOption19 = 0 for both lights , then put back discovery in configuration.yaml and restarted HA. Still the same result.
I have observed one thing though, at times when I restart I get back both the entities : parking_light as well as parking_light_2 , same for temple light but they usually dissapear on the next restart.

Have you deleted the discovered entities in configuration / entity registry like I told you to?

You also need to delete all items in this topic on your mqtt server:

homeassistant/switch/#

Eureka! I found them.
@tom_l , sorry for ignoring part of your instructions. Yes you are right, these entries were in the /config/.storage/core.entity_registry & /config/.storage/core.restore_state files. I deleted them from both places and now I have the right entity show up. I wasn’t aware that discovered items are stored in the .storage directory.
Thank you so much for your help!! Appreciate your patience!!

For others who would face this, i deleted the following entries from these files:

deleted from /config/.storage/core.entity_registry

            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "switch.parking_light",
                "name": null,
                "platform": "wemo",
                "unique_id": "201612K00DFF93D"
            },
            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "switch.temple_light",
                "name": null,
                "platform": "wemo",
                "unique_id": "201612K00DF3CCC"
            },

deleted from /config/.storage/core.restore_state
        {
            "last_seen": "2019-06-29T13:59:04.006658+00:00",
            "state": {
                "attributes": {
                    "friendly_name": "Parking Light"
                },
                "context": {
                    "id": "19d3b737159b45dd91d370ca0d5ec8ff",
                    "parent_id": null,
                    "user_id": null
                },
                "entity_id": "switch.parking_light_2",
                "last_changed": "2019-06-29T13:55:39.354573+00:00",
                "last_updated": "2019-06-29T13:55:39.354573+00:00",
                "state": "unavailable"
            }
        },
        {
            "last_seen": "2019-06-29T14:07:29.744190+00:00",
            "state": {
                "attributes": {
                    "friendly_name": "Temple Light",
                    "source_type": null
                },
                "context": {
                    "id": "c66128ec0bc04aabb916298bcf978a26",
                    "parent_id": null,
                    "user_id": null
                },
                "entity_id": "device_tracker.temple_light",
                "last_changed": "2019-06-29T14:05:21.383364+00:00",
                "last_updated": "2019-06-29T14:05:21.383364+00:00",
                "state": "not_home"
            }
        },
        {
            "last_seen": "2019-06-29T14:07:29.744190+00:00",
            "state": {
                "attributes": {
                    "friendly_name": "Temple Light"
                },
                "context": {
                    "id": "f249167cbaba4320ba4d875a4c968377",
                    "parent_id": null,
                    "user_id": null
                },
                "entity_id": "switch.temple_light_2",
                "last_changed": "2019-06-29T14:05:22.605400+00:00",
                "last_updated": "2019-06-29T14:05:22.605400+00:00",
                "state": "off"
            }
        },