rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.84k stars 546 forks source link

How to remove a device? #871

Open Forge36 opened 2 years ago

Forge36 commented 2 years ago

I recently configured a fan. I skipped speed control and the light thinking I could go back and add them later (I couldn't tell which values did what offhand)

Prior to v4.0 it was possible to remove a configuration and readd it. After v4.0 this would remove all configurations.

Edit lacks the original options to allow me to reconfigure the device as multiple entities.

almighty059 commented 2 years ago

@Forge36 open the device and click on the three dots in the Device Info box.

Screenshot 2022-06-15 155026

donburch888 commented 2 years ago

Well, i am missing the 3 dots in the device info box :-(

image

I can't add entities, and i can't delete the device to start again.

Forge36 commented 2 years ago

I am also missing the 3 dots.

regevbr commented 2 years ago

This doesn't work for me... the control entities are removed but not the device itself. Trying to remove from the config flows return an error and indicates to look at the logs which shows:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 533, in async_step_configure_device
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 237, in validate_input
    data[CONF_DEVICE_ID],
KeyError: 'device_id'

Error unloading entry localtuya for localtuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 478, in async_unload
    result = await component.async_unload_entry(hass, self)
  File "/config/custom_components/localtuya/__init__.py", line 308, in async_unload_entry
    hass.data[DOMAIN][entry.entry_id][UNSUB_LISTENER]()
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 587, in <lambda>
    return lambda: self.update_listeners.remove(weak_listener)
ValueError: list.remove(x): x not in li

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 478, in async_unload
    result = await component.async_unload_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 603, in async_unload_entry
    return await component.async_unload_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 172, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
lindsaymarkward commented 2 years ago

Is it possible to remove devices/entities by manually editing the .storage or something?

CloCkWeRX commented 2 years ago

This doesn't work for me... the control entities are removed but not the device itself. Trying to remove from the config flows return an error and indicates to look at the logs which shows:

I think this is a duplicate of #897 (though this... predates it).

Scope666 commented 2 years ago

I switched 2 devices from stock firmware to Tasmota, I'm trying to delete those 2 devices from my existing installation, but I'm getting an error:


Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 533, in async_step_configure_device
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 237, in validate_input
    data[CONF_DEVICE_ID],
KeyError: 'device_id'
userMak commented 1 year ago

Hi, I can not delete a device. Anyone found a workaround, or at least what is the problem??

noob4722019 commented 1 year ago

I couldn't edit the entities of a device, so I made another device with the same details, when I saved it, it bugged out, it's now not visible, and when I got to edit a device, it just fails. Need to somehow delete these bugged devices.

almighty059 commented 1 year ago

If it doesn't work using the three dots then I go to Devices and Services and find it in the Entities tab and try to delete it like that. If I still can't then I clear the cache, restart HA, double check to make sure it hasn't been deleted and then I remove it in either /config/.storage/core.device_registry for core devices, /config/.storage/core.entity_registry for core entities, or /config/.storage/core.config_entries for entities/devices from integrations like LocalTuya. I like using FIle Editor to make these edits because you need to click "Save" so that's a nice safety feature as opposed to Studio Code Server just auto-saving it. You also might have to enable access to the .storage file in order to access these files. I also suggest downloading a backup copy of the file just in case you do make a mistake. It's always better to be safe than sorry. It's relatively easy to delete an entity within these files as long as you only delete the entity and nothing more. BE VERY CAREFUL...!! In my screenshots, you should only delete what is highlighted in blue. If you accidentally delete the comma as opposed to just what's in the block of blue highlighting then your system will probably lock or you will get an error when Checking Configuration on the YAML tab in Developer Tools. (As a side note ALWAYS "Check Configuration" every time and any time you're about to restart your HA.

Screenshot 2022-09-24 030911 Screenshot 2022-09-24 034309

neuronflow commented 1 year ago

I cannot see the 3 dots, and also no download diagnostics button? Is there a way to make them appear?

Forge36 commented 1 year ago

I still haven't been able to remove devices. I ended up scratching everything and removing the integration and re-adding everything and fully migrating to localtuya. I suspect it's possible to dig into the config files/raw data though I've not taken the time for that yet.

neuronflow commented 1 year ago

I managed to get the dots visible after disabling and reenabling localtuya and restarting HA. Then I could delete the device.

aogriffiths commented 1 year ago

Just thought I'd share my experience with the "16A Tuya Smart Wifi Plug UK" here

Screenshot 2022-11-22 at 18 44 34

I used the following DP (data points):

And could have (but didn't bother with:

This gave me the following in the localtuya UI Screenshot 2022-11-22 at 18 42 53

aogriffiths commented 1 year ago

My last comment was just to add the information to this thread (which has become very informative).

I did find some bugs and Ricky steps along the way:

  1. Adding the scaling factors - the input filed won't allow typing them as a decimal number like 0.1 or 0.001 - the way to do it is type the number elsewhere and paste it in
  2. The UI to add the device works, if you get everything right first time. Going back to edit/reconfigure the device generally failed for me, loosing all the config or making the device unusable. I would then have to delete it, or worse still delete the entire localtuya integration, and start again.
  3. Sometimes when deleting a device all it's entities got deleted buy the device itself would not go. In this case the only way to get rid of it was to delete the entire localtuya config and start again.
  4. I made the current / power / voltage both attributes of the switch entity AND entities in their own right (e.g. for current I configured switch.switch_1.current AND sensor.switch_1_current)
  5. As a general comment for good practice in home assistant, I paid close attention to naming conventions so the entities created didn't have names which might clash with other entities in the future (e.g. I made sure I used "switch_1" not "switch" and "switch_1_current" not "current" etc)

Not sure if these are tips and tricks, or bugs, or feature requests - that's up to the maintainers of the fantastic localtuya. Thanks!

aogriffiths commented 1 year ago

and finally, I have a question. Why does Power not equal Current * Voltage in so many of the comments and screenshots above - including my own?

I have current = 0.12A, voltage = 240.5V so surely power should equal 28.86W but in the UI (both the Tuya App, and in Home Assistant) power is showing as 20.8W. The maths is similar for many other's examples in this thread but it seems wrong to me. Am I missing something?!

Leblayd commented 1 year ago

To help with removing devices:

I found it eventually starts properly deleting, even from the UI.

  1. Remove dead device
  2. If entity is removed but device is still there a. Edit the removed device with LocalTuya's configuration, which re-adds it b. Go back to step 1. (repeat like 5 times max)
AngelouDi commented 1 year ago

To help with removing devices:

I found it eventually starts properly deleting, even from the UI.

1. Remove dead device

2. If entity is removed but device is still there
   a. Edit the removed device with LocalTuya's configuration, which re-adds it
   b. Go back to step 1. (repeat like 5 times max)

This worked apparently.

bedge117 commented 10 months ago

To help with removing devices: I found it eventually starts properly deleting, even from the UI.

1. Remove dead device

2. If entity is removed but device is still there
   a. Edit the removed device with LocalTuya's configuration, which re-adds it
   b. Go back to step 1. (repeat like 5 times max)

This worked apparently.

For those of you who have stumbled upon this thread because you are about to rip your hair out over these hanging devices, follow the steps below:

This has worked for me 100% of the time. First thing you want to do is go into your localtuya configuration → edit the device you are trying to remove → (leave your entity checked, and submit → on the entity screen, toggle the passive setting on entity→ submit → reload integration, and that’s it!!!

Go into your device and delete the device. This will also delete the entity.

(Note: If you have multiple entities, you may have to do this on each entity when you are editing the config.)

image