Removing MQTT sensor

Tags: #<Tag:0x00007f738b85a2e0>

I have Sonoff TH, it used to have 1 AM2302 sensor, now it has two so the name of the first sensor changed (“am2301” -> “am2301_1”) and now HA considers “am2301” gone and I see constant exceptions in the journalctl:

Jun 09 11:29:42 aikhass hass[6607]: 2020-06-09 11:29:42 ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on 'tele/tasmota_81ED08/SENSOR': '{"Time":"2020-06-09T02:29:42","AM2301-01":{"Temperature":22.4,"Humidity":33.2,"DewPoint":5.4},"AM2301-03":{"Temperature":19.1,"Humidity":17.5,"DewPoint":-6.2},"TempUnit":"C"}'
Jun 09 11:29:42 aikhass hass[6607]: Traceback (most recent call last):
Jun 09 11:29:42 aikhass hass[6607]:   File "/home/aik/homeassistant/lib/python3.8/site-packages/homeassistant/components/mqtt/debug_info.py", line 34, in wrapper
Jun 09 11:29:42 aikhass hass[6607]:     _log_message(msg)
Jun 09 11:29:42 aikhass hass[6607]:   File "/home/aik/homeassistant/lib/python3.8/site-packages/homeassistant/components/mqtt/debug_info.py", line 24, in _log_message
Jun 09 11:29:42 aikhass hass[6607]:     messages = debug_info["entities"][entity_id]["subscriptions"][
Jun 09 11:29:42 aikhass hass[6607]: KeyError: 'sensor.tempmaster_am2301_humidity'

How do I stop these exceptions? Googling suggests manual editing of various files in .homeassistant which seems overkill.

Did you use auto-discovery or manual configuration in yaml ?

uff. just saw the response. Always auto-discovery.

Still having the problem. With most sensors I can run MQTT-Explorer and remove those from mosquitto and things are fine but some sensors are just stuck - they do not appear anywhere in the HA UI but I keep getting

Jul 10 10:13:47 aikhass hass[1067]: 2020-07-10 10:13:47 ERROR (MainThread) [homeassistant.util.logging] Exception in attributes_message_rec
eived when handling msg on 'tele/tasmota_832E7D/HASS_STATE': '{"Version":"8.3.1(sensors)","BuildDateTime":"2020-05-18T15:41:26","Module or 
Template":"Sonoff TH","RestartReason":"Power On","Uptime":"0T16:25:05","Hostname":"tasmota_832E7D-3709","IPAddress":"192.168.10.143","RSSI"
:"80","Signal (dBm)":"-60","WiFi LinkCount":1,"WiFi Downtime":"0T00:00:03","MqttCount":1,"LoadAvg":19}'                                    
Jul 10 10:13:47 aikhass hass[1067]: Traceback (most recent call last):                                                                     
Jul 10 10:13:47 aikhass hass[1067]:   File "/home/aik/homeassistant/lib/python3.8/site-packages/homeassistant/components/mqtt/debug_info.py
", line 34, in wrapper                                                                                                                     
Jul 10 10:13:47 aikhass hass[1067]:     _log_message(msg)                                                                                  
Jul 10 10:13:47 aikhass hass[1067]:   File "/home/aik/homeassistant/lib/python3.8/site-packages/homeassistant/components/mqtt/debug_info.py
", line 24, in _log_message                                                                                                                
Jul 10 10:13:47 aikhass hass[1067]:     messages = debug_info["entities"][entity_id]["subscriptions"][                                     
Jul 10 10:13:47 aikhass hass[1067]: KeyError: 'sensor.outdoor_status'                                                                     

How to remove sensor completely?

I think I’m also seeing similar issue with one of my tasmota-tuya converted lights. I have several that are fine, but one shows the same Exception error in HA Log and points to this non-existent entity:

KeyError: ‘light.bathroom_tasmota’

Is it not ok to rename entities in HA if they are discovered using auto-discovery?
I did not use auto-discovery really at all until I started using tasmota.
Is there some “cached” entity names that may need a refresh?
–Doug

If you have renamed an entity, you might need to restart HA.

Try, in tasmota console : setoption19 0

Thank you for the suggestion, I tend to not restart HA as much these days now that you can reload scripts and automations.
Seems to have stopped the error for now. I like the autodiscovery, just need to get used to it! Thanks again!
–Doug