Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tuya TS0041 TS0042 TS0043 - no battery #2227

Closed
provinzio opened this issue Feb 26, 2023 · 77 comments · Fixed by #2288
Closed

[BUG] Tuya TS0041 TS0042 TS0043 - no battery #2227

provinzio opened this issue Feb 26, 2023 · 77 comments · Fixed by #2288
Labels
Tuya Request/PR regarding a Tuya device

Comments

@provinzio
Copy link

provinzio commented Feb 26, 2023

Describe the bug
The Battery value in Home Assistant is always at 100 %. Eventhough I use the switches for over a year now and already had to change the batteries.

To Reproduce
Using automatically discorvered quirks e.g. zhaquirks.tuya.ts0042.TuyaSmartRemote0042TO

Expected behavior
Correct battery value

Additional context
Related fixed issue from zigbee2mqtt Koenkk/zigbee2mqtt#6331
Related misbehavior of the buttons with the quirks #1746

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label Feb 26, 2023
@javicalle
Copy link
Collaborator

javicalle commented Feb 27, 2023

Related fixed issue from zigbee2mqtt Koenkk/zigbee2mqtt#6331

The issue is not fixed in Z2M.
The fix from your link generated other errors:

and the code has been reverted and is not present in the current version:

Actually the same issue is present in Z2M and not fixed:

From the ZHA quirk point of view I would suggest to remove (in the replacement part) all the PowerConfiguration clusters except from endpoint 1. IE: for the TuyaSmartRemote0042TO quirk:

class TuyaSmartRemote0042TO(CustomDevice):
    """Tuya 2-button remote device with time on out cluster."""

    signature = {
        # SizePrefixedSimpleDescriptor(endpoint=1, profile=260, device_type=0, device_version=1, input_clusters=[0, 1, 6], output_clusters=[10, 25]))
        # SizePrefixedSimpleDescriptor(endpoint=2, profile=260, device_type=0, device_version=1, input_clusters=[1, 6], output_clusters=[])
        MODEL: "TS0042",
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    OnOff.cluster_id,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            2: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
                INPUT_CLUSTERS: [
                    PowerConfiguration.cluster_id,
                    OnOff.cluster_id,
                ],
                OUTPUT_CLUSTERS: [],
            },
        },
    }
    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.REMOTE_CONTROL,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    TuyaSmartRemoteOnOffCluster,
                ],
                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
            },
            2: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: zha.DeviceType.REMOTE_CONTROL,
                INPUT_CLUSTERS: [
                    TuyaSmartRemoteOnOffCluster,
                ],
                OUTPUT_CLUSTERS: [],
            },
        },
    }

    device_automation_triggers = {
        (SHORT_PRESS, BUTTON_1): {ENDPOINT_ID: 1, COMMAND: SHORT_PRESS},
        (LONG_PRESS, BUTTON_1): {ENDPOINT_ID: 1, COMMAND: LONG_PRESS},
        (DOUBLE_PRESS, BUTTON_1): {ENDPOINT_ID: 1, COMMAND: DOUBLE_PRESS},
        (SHORT_PRESS, BUTTON_2): {ENDPOINT_ID: 2, COMMAND: SHORT_PRESS},
        (LONG_PRESS, BUTTON_2): {ENDPOINT_ID: 2, COMMAND: LONG_PRESS},
        (DOUBLE_PRESS, BUTTON_2): {ENDPOINT_ID: 2, COMMAND: DOUBLE_PRESS},
    }

@MattWestb
Copy link
Contributor

All TS004X quirks shall being converted to EnchantedDevice for not getting problems with new versions of them and all is remotes like TS004F that is converted.

Likely the magic can fixing this issue 2.

The TS004F we is using the OnOff on out cluster and that is making little problems with defaultresponse that need being sent in reversed direction that ZHA cant doing but i think its not the problem here.

@javicalle
Copy link
Collaborator

@provinzio Are you using the quirk from #1746 or is the quirk from latest HA version?
@cordvision Do you mind to test the proposed change from #2227 (comment) and check the battery behavior?

@provinzio
Copy link
Author

@javicalle I am currently using the quirk from the latest HA version

@javicalle
Copy link
Collaborator

@javicalle I am currently using the quirk from the latest HA version

Could you try with the custom quirk from #1746 (comment)

You will need to remove and repair the device after enable the local quirk.
Other user is reporting 'jumping' values after apply the quirk. For that behavior I suggest to remove the PowerConfiguration (my previous comment).

@provinzio
Copy link
Author

provinzio commented Mar 1, 2023

tl;dr I implemented your propsed quirk, a battery level != 100% gets detected which looks promising. Everything else seems normal at first. I will wait for 1-3 days and check in again whether the battery level dropped accordingly and whether the buttons still work as expected


I did the following steps in this order

  1. Downloaded TS0041 TS0044 TS0042 - missing presses and LED flashing #1746 (comment)
  2. Adjusted it for 3 buttons ts0043_custom.py.txt
  3. Removed the PowerConfiguration as you said ts0043_custom_removed_PowerConfiguration.py.txt
  4. Uploaded the quirk to Home Assistant
  5. Removed the device in Home Assistant
  6. Repaired the device
  7. Check which quirk was used > "zhaquirks.tuya.ts0043.TuyaSmartRemote0043TO"; thats not my quirk... Do I have to restart HA or something, so that the new quirk can be used?

But, the battery gets detected as 74% which is not 100%. It looks like the repairing did something. Perhaps I wasn't using the latest quirk after all and was stuck with an older quirk?

Clicking the buttons of the switch does not fire an event, automations do not get triggered.

  1. Reload ZHA
  2. Check which quirk was used; now my quirk gets detected > "class": "ts0043_custom_removed_PowerConfiguration.TuyaSmartRemote0043TO"
  3. clicking buttons triggers events anautomations. everything seems normal
  4. I'll test your proposed quirk (see 3) and report back, whether it works.

@MattWestb
Copy link
Contributor

ZHA is only loading quirks then its starting so its not being loaded on the flay.
Then the first paring was with the old quirk can you later deleting the remote and waiting one minute and pairing it new and testing how its working ?

Dont hurry we have lot of time until next HA is being released so better doing the test well ;-))

@provinzio
Copy link
Author

Ok I will do the following steps and check out whether the device functions normally

  1. Upload Quirk
  2. Reload ZHA
  3. Delete device
  4. Wait 1 minute
  5. Repair device

@provinzio
Copy link
Author

Ok I will do the following steps and check out whether the device functions normally

1. Upload Quirk

2. Reload ZHA

3. Delete device

4. Wait 1 minute

5. Repair device

I realized, that the battery is at 100 % after doing this. So this is currently bad when looking at the battery information.

I am out of time for today, I'll try to remove the quirk tomorrow and setup the latest HA quirk, which might have given me the correct battery info (see my post above).

@provinzio
Copy link
Author

Quick update. The battery was updated after a while. So I am keeping the proposed quirk and check whether the battery issue (and perhaps also the missing clicks) are fixed with it.

@cordvision
Copy link

@javicalle Sorry, I was away for a couple days. I would be happy to test it and report back. I'm a little confused which is the latest quirk that needs testing. Any chance you could upload it as a text file? I have the TS0044 switch (4 buttons / 12 different actions). I just want to avoid editing the quirk myself and possibly introducing issues (I'm fairly new with Home Assistant).

@provinzio
Copy link
Author

@cordvision ts0044_custom_removed_PowerConfiguration.py.txt

I am currently testing ts0043_custom_removed_PowerConfiguration. Until now I don't think that I had missing clicks. The battery value is jumping between a value and 100%. Ideas?

grafik

@javicalle
Copy link
Collaborator

@provinzio which quirk are you testing? Is the TuyaSmartRemote0043TO from your previous comment?
Whitout logs it would be hard to know but it seems that device is reporting double the battery, once with 100% and other (maybe) with the good one.

My assumption was that the extra PowerConfiguration were responsible of it, but the quirk have remove it so... no idea.
Could you attach the diagnosis file from your device with the quirk?

Also could be interesting to enable the debug logs and check the battery reports from your device. It is probably that device report itself the battery status over time but maybe also reports when any key is pressed, can you check?

@provinzio
Copy link
Author

@javicalle yep TuyaSmartRemote0043TO from ts0043_custom_removed_PowerConfiguration.py.txt

Do you mean this file? If not please give me a hint where I can find the relevant file :)
zha-1b4a270315098112f906ebf272ff388d-_TZ3000_gbm10jnj TS0043-4c9b7002357cc58c20cbf2c2afa52d07.json.txt

I find the battery_percentage_remaining value interesting. It's at 140, eventhough the value in Home Assistant says 70 %.

The battery jumping is periodic and also through the night. I don't think that it interacts with any clicks or something else.
The 100% value stays ~20 minutes. The "real" value stays for ~40 minutes. Its not exactly 20/40 min but kind of. Which makes a whole cycle of 100 % back to the "real" value ~60 min long. Looks fishy to me, but I have no idea why it does that.

grafik

@MattWestb
Copy link
Contributor

Zigbee is using 1-200 for battery % and 255 is not known so preposition is 0.5%

@provinzio
Copy link
Author

provinzio commented Mar 7, 2023

I am stuck on this... I updated the quirk for all variants according to your suggestion. All show the same battery behavior.

@javicalle looking for your guidance. Do you have an idea what we could check next? Is it worth to look at the debug logs? I am unfamiliar with that but could dig into it.

@MattWestb
Copy link
Contributor

I only having some TS004F devices but the 4 scene switch is very similar and different and is sending battery report from button 2 or 3 press (i dont remember with).

Can you posting debug log from TS0044 then making pressing of all buttons and waiting 10 seconds between so we can see what the switch is doing (or not) with your updated quirk ?

Then looking on your posted graf i think its normal battery readings.
Zigbee is recommending reading the battery then the radio is in stable idle state for not getting the reading stable and i think tuya have not reading that PM.
If reading then the radio is active / not stable idle state you is getting higher if the transmission is going well / fast and if its need repeating / waiting the reading is being lower.
So i think the reading is OK for the device and its better then Xiaomi that is showing 100% most of the time until they is dead.

If you is getting high readings and can see its moving little up and down i think its all we can getting from the device then its how the device firmware is being done.

@nibo2
Copy link

nibo2 commented Mar 7, 2023

Pitching in here... I have had ts0044_custom_removed_PowerConfiguration.py.txt installed now for a few days on a wall switch. Same sawtooth 40+20 min cycle pattern as you others.

Here is a snippet from the logs from this night (TS0044 device identifier 0xEF55).
Log ZHA TS0044 0xEF55.txt

Some observations in the logs:

  • There are two distinctively different sets of packets received from the client in the 40+20 min cycle. I put some blank lines around the interesting bits for readability
  • "last_seen" does not seem to be reset ever (?)
  • A restart of ZHA, or indeed the entire HA, does not affect the timing of the 40+20 min pattern. Suggesting it is in no way initiated or reset by HA?

@nibo2
Copy link

nibo2 commented Mar 7, 2023

Log ZHA TS00440xEF55 buttons.txt

Timestamps (c:a):

  • 10:09:45 Caught typical 40+20 cycle set of packets. Also confirmed - the wall switch flashed 4 LEDs at this time while I was just standing next to it waiting
  • 10:10.06 Single press Button 1
  • 10:10:31 Double press Button 2
  • 10:11:04 Long press Button 3

@MattWestb
Copy link
Contributor

The device is rejoining the network that shall not happening if all things is OK.
What is your coordinator type TI or EZSP ?
Is the device have the coordinator as it parent or is it having one good or bad router as parent ?
Look on the network map after updating it so its current.

And the device is sending one updated battery around 60 min and its OK but its have loosing the contact with the network (somthing is making it thinking that) and after the first rejoining and reporting next reporting is OK 60 min later and then next is start rejoining and sending battery report.

@MattWestb
Copy link
Contributor

flashed 4 LEDs = its rejoining the network :-((

@nibo2
Copy link

nibo2 commented Mar 7, 2023

I have neither TI or EZSP. It's Dresden.

@nibo2
Copy link

nibo2 commented Mar 7, 2023

The wall switch device has a good connection to a IKEA TRADFRI bulb, 2m away from it (always on). I have 3 TS0044 units and they all behave the same way. One has the coordinator directly as parent.

@cordvision
Copy link

I am stuck on this... I updated the quirk for all variants according to your suggestion. All show the same battery behavior.

@javicalle looking for your guidance. Do you have an idea what we could check next? Is it worth to look at the debug logs? I am unfamiliar with that but could dig into it.

ts0041_custom_removed_PowerConfiguration.py.txt ts0042_custom_removed_PowerConfiguration.py.txt ts0043_custom_removed_PowerConfiguration.py.txt ts0044_custom_removed_PowerConfiguration.py.txt

I uploaded the ts0044 quirk (I of course removed the .txt ending). After re-installing the device and re-starting HA, the custom quirk doesn't seam to have loaded. Under "Zigbee info" for the device, I see "Quirk: zhaquirks.tuya.ts0044.TuyaSmartRemote0044TO". I've used other custom quirks for this device before, and never had that issue. How do I ensure the custom quirk gets loaded?

@cordvision
Copy link

@provinzio Do you know if the sleep issue (first button pressed is ignored after a few hours of inactivity) is solved for the ts0044 with the quirk you posted?

@MattWestb
Copy link
Contributor

I cant testing it then my RaspBee is out of function for some time :-((

Is the switch that is having the coordinator as parent doing the strange blinking / rejoining as the other ones ?
Also have updated the IKEA lights so they is not running on old bad firmware with routing problems?

I think in the end we need sniffing how the system is setting u the switches in real.

@MattWestb
Copy link
Contributor

@cordvision You see if its loading the quirk in HA log then system is starting if you have debug logging enabled also what quirk the device is getting then the device is loaded of ZHA.

@MattWestb
Copy link
Contributor

@cordvision What coordinator is you using ?

@cordvision
Copy link

cordvision commented Mar 7, 2023

I'm using a conbee II. Previously and also for other devices, if I go to the device info tab and then click on "zigbee info", I would usually see the custom quirks name. In other words, I would

expect to see this: Quirk: ts0044_custom_removed_PowerConfiguration.py

However, I see this: Quirk: zhaquirks.tuya.ts0044.TuyaSmartRemote0044TO

@provinzio
Copy link
Author

I haven't looked into the debug messages and thought that I should be able to see the updates in HA GUI

@cordvision
Copy link

I noticed something with my two switches in regards to battery percentage reporting... please see attached image:

fb55ac38-6bbe-419f-957b-af7e718eb006

@MattWestb
Copy link
Contributor

The with dots is one updated / later version then the first was without.
Can you posting the 6 first (or all) numbers of the IEEE from both device i like to knowing is its Silabs chips inside or updated to Telink.

@cordvision
Copy link

Aubess: IEEE: dc:8e:95:ff:fe:a0:5b:c1
Moes: IEEE: dc:8e:95:ff:fe:30:68:34

What can you tell from those?

@javicalle
Copy link
Collaborator

They do NOT however show as updated in the HA GUI. Probably because there is no change in value.

IIRC that's true. HA don't considerer the value update until it changes.

@MattWestb
Copy link
Contributor

Both is using Silabs chips that good but i think the firmware is little different.
San also look on software version and app version on basic cluster.

@cordvision
Copy link

Where do I find the info for the software/app version? (I’m fairly new at HA)

@TheJulianJES
Copy link
Collaborator

Go to the device page -> three dots on the left -> Manage Zigbee device -> Clusters tab -> select Basic cluster in the first dropdown, select sw_build_id in the second dropdown, click "Read Attribute" and press a button on the remote to wake it up.
Then read app_version (also on the Basic cluster)

@cordvision
Copy link

Its exactly the same for both switches: App Version 66
Sw Build: Value: None (actually shows "None"... updates from an empty field to "None" once I press a button on the switch)

I made another interesting discovery: I got both switches to report battery percentage correctly. Here is what I did:
I tried multiple times to remove the device that reported battery values incorrectly... restarted HA, added the device, restarted HA again... but that didn't work. What finally worked was to remove the switch... restart HA... and then just wait. After about 30mins the switch appeared again as a device (even though I haven't added it). Since then it reports battery percentage correctly. Not sure what happened, I decided to repeat the procedure again... When I remove the switch and restart HA, the switch eventually appears again without the need to use the "add device" button. Is that normal behavior?

@MattWestb
Copy link
Contributor

Was you deleting the device from the device card before restring HA ?
Then ZHA is deleting it in the database but if the device was sleeping it was not getting the leave without rejoining (= factory reset and forgetting the network settings so it cant rejoining the network) and can late rejoining the network and ZHA is setting it up as new joining then its not knowing the device but is having the network security setting for it.
I think if you is waking up the device then deleting it its cant rejoining and must being added normal way after you have restarting HA and no "automatic joining" can being done of the device.

By the was tuya is normally using app version change for different builds of the firmware but is not 110% but likely your device is running the same firmware.

The good thing is looks like the battery reporting is working OK on all your devices now :-)))

@javicalle
Copy link
Collaborator

So, which one will be the correct approach to that issue?
To apply the modifications in all the TS004X quirks family? (there are 3-4 quirks in every file)

@MattWestb
Copy link
Contributor

I think TS004F is not needed and if i taking care or it then i have 2 of the problem devices (Dimmer switch and rotating knob and the first need extra config from ZHA).

So TS0041, 42, 43, 44 and 46 (the last is pity new and but i think is very like the 44 version) getting tuya magic, SKIP_CONFIGURATION and deleting power cluster that is on not EP1.

Is that you is using and its working @cordvision ?

@javicalle
Copy link
Collaborator

@cordvision please, confirm the quirks version that you are using. This way we can point just to the validated ones if other users are getting problems with the update.

@cordvision
Copy link

Great test results! I have been running SKIP_CONFIGURATION on three TS0044 devices for 18+ hours. Looking at the logs:

  • 2 out of 3 devices sent battery percentage and voltage info on startup
  • All 3 sent have sent 1 battery percentage and voltage packet each since startup. This would indicate that the devices are indeed updating once a day or so. Which is perfect
  • No lost connection. Which means no need to rejoin network
  • No bogus 100% battery packets
  • Not even one first-press-ignored when using the devices (although there hasn't been very much use)

ts0044_custom_removed_PowerConfiguration_SKIP_CONFIGURATION.py.txt

I'm using the quirk from this post. The battery percentage looks fine now, but I noticed that it hasn't updated in 17 hours. I have to see if it updates only when there is an actual change in battery level (which might take some time).

@MattWestb Yes, I deleted the device from HA (but I did it without the switch being activated while doing so), I then restarted HA... and just waited until the device added itself again.

@provinzio
Copy link
Author

In my case, my 3 devices are reporting battery about once every 4 hours. They do NOT however show as updated in the HA GUI. Probably because there is no change in value. So that's fine. Logs:

2023-03-09 01:28:15.572 DEBUG (MainThread) [zigpy.zcl] [0x38F0:1:0x0001] Attribute report received: battery_percentage_remaining=172, battery_voltage=29 2023-03-09 01:36:02.299 DEBUG (MainThread) [zigpy.zcl] [0xFC43:1:0x0001] Attribute report received: battery_percentage_remaining=150, battery_voltage=28 2023-03-09 02:03:15.743 DEBUG (MainThread) [zigpy.zcl] [0x3106:1:0x0001] Attribute report received: battery_percentage_remaining=154, battery_voltage=28 2023-03-09 05:25:36.660 DEBUG (MainThread) [zigpy.zcl] [0x38F0:1:0x0001] Attribute report received: battery_percentage_remaining=172, battery_voltage=29 2023-03-09 05:33:28.748 DEBUG (MainThread) [zigpy.zcl] [0xFC43:1:0x0001] Attribute report received: battery_percentage_remaining=150, battery_voltage=28 2023-03-09 06:01:00.218 DEBUG (MainThread) [zigpy.zcl] [0x3106:1:0x0001] Attribute report received: battery_percentage_remaining=154, battery_voltage=28 2023-03-09 09:22:52.531 DEBUG (MainThread) [zigpy.zcl] [0x38F0:1:0x0001] Attribute report received: battery_percentage_remaining=172, battery_voltage=29 2023-03-09 09:31:05.316 DEBUG (MainThread) [zigpy.zcl] [0xFC43:1:0x0001] Attribute report received: battery_percentage_remaining=150, battery_voltage=28 2023-03-09 09:58:39.322 DEBUG (MainThread) [zigpy.zcl] [0x3106:1:0x0001] Attribute report received: battery_percentage_remaining=154, battery_voltage=28

@cordvision nibo2 reported, that the battery reports aren't visualized in HA but only come up in the debug logs when the value doesn't change

@provinzio
Copy link
Author

provinzio commented Mar 10, 2023

I think TS004F is not needed and if i taking care or it then i have 2 of the problem devices (Dimmer switch and rotating knob and the first need extra config from ZHA).

So TS0041, 42, 43, 44 and 46 (the last is pity new and but i think is very like the 44 version) getting tuya magic, SKIP_CONFIGURATION and deleting power cluster that is on not EP1.

Is that you is using and its working @cordvision ?

@MattWestb I am currently using these files. Please not, that I only edited the quirks I use, as I cannot test the others.

@MattWestb
Copy link
Contributor

Great and we dont have all devices so we cant testing all for sure.
But all TS004X and some other devices is working the same way so shall being no braking changes for all devices. The magic Z2M is using on all new tuya device and the not binding the power is done on the TS004X remotes and looks working OK for all. And sniffs i have seen and doing is tuya normally not setting up binding and reporting then adding devices.

I saying Javicalle batch all quirks with the changes and making one PR !! :-))

@nibo2
Copy link

nibo2 commented Mar 10, 2023

Hopefully the battery values will not change for another week or so. Otherwise the battery will never last 2 years as advertised :-)

Anyway, the logs show battery % and V still being sent happily every 4 hours.

@TheJulianJES
Copy link
Collaborator

Not really any new information, but I have a Zemismart button that matches TuyaSmartRemote0041TO.
I've never ended up using it, but I remember that the battery would also drain after a few days or so (or maybe a week?).

So I'd also say that SKIP_CONFIGURATION should just be applied to TS004x remotes.

And you also wanted to add EnchantedDevice? Is that really needed for these devices though? (It causes a lot of attribute reads)
In general, is it really necessary that we read all 6 attributes (per Tuya device) every time HA is restarted?
(For battery devices, this also doesn't work and just causes a lot of traffic, as the reads will be repeated up to three times I think?)

@MattWestb
Copy link
Contributor

If SKIP_CONFIGURATIONis working on most devices go for it !!

@javicalle and i have the meaning that we need adding the EnchantedDevice on more and more new devices also that is fitting in quirk that is working for older devices so in the long run we is getting less problems with device not working OK.
Also the implementation is is sending 6 attributes then the device is doing one new joining and on every start of ZHA is trying doing the same but they in being sent then the coordinator is not online so they is lost in the back hole and not being sent to the coordinator.

attr_to_read = [4, 0, 1, 5, 7, 0xFFFE]

Also all sniffs i have looking on from pairing devices with tuya ZVGW is doing it for all devices and Z2M is putting it on all new added tua devices.
It can being that some device is changing behavior with the magic and need some patching but then they is working more normal after the fix and i think its the right way to going.

@TheJulianJES
Copy link
Collaborator

Also the implementation is is sending 6 attributes then the device is doing one new joining and on every start of ZHA is trying doing the same but they in being sent then the coordinator is not online so they is lost in the back hole and not being sent to the coordinator

The current way of always reading the 6 attributes when the class is initialized isn't great IMO.
Even if the attribute reads are never actually sent to the network, we shouldn't rely on behavior that's different if ZHA isn't fully started yet.

And you also mentioned that devices rejoin after those six attributes are read?

It could only be called on bind(), but obviously that won't be called if SKIP_CONFIGURATION is enabled. But a better/proper way to do this should be figured out. (The current implementation also has issues with testing I think)

For now, I'd only use EnchantedDevice if necessary. If the remotes don't need it, I wouldn't add it.

@MattWestb
Copy link
Contributor

Its not being sent on rejoining then the quirk is already loaded for the device the device must being one new joining for it being sent to the device (have sniffing it and its need being sent some milli seconds after the device is getting getting the network key or is not working.

So if one user is baying one device and joining it ts getting the magic and never more if not deleting it in ZHA and waiting one minute and adding it new (if taking out the battery then is being retested its losing the magic saved in the chip).

You do what you like and taking care of all TS04X devices also the TS004F.

@javicalle
Copy link
Collaborator

It seems that new versions for signatures that already have been quirked are needing the EnchantedDevice. It is very dificult to match the real ones that needed it from the ones that doesn't.
I have seen an implementation in the bind() function and it will be doable, but if the SKIP_CONFIGURATION prevents from the bind() I don't know how can be done.
I have a local refactor for the MCU classes that cast the Tuya spell in the __init__, but from what is exposed is not the best approach.

I will try to figure a new approach. Anyy advice or recomendation will be welcomed.

@TheJulianJES
Copy link
Collaborator

TheJulianJES commented Mar 13, 2023

This is where async_configure is called (join + reconfiguration): zha/core/channels/base.py
(Restart HA should only call async_initialize, but not async_configure)

So if SKIP_CONFIGURATION is enabled, no binding and no reporting will be set up.
There's no perfect way to do this atm, but we could leave SKIP_CONFIGURATION disabled and then just override bind() and configureReporting() for required clusters: see example from LocalDataCluster

I do like that EnchantedDevice is just a quick replacement for CustomDevice. Since it somewhat doesn't matter from which bind() method we make these calls, I think we could use a replacement for any cluster (that's registered as a channel in ZHA and allows binding (Basic cluster is blocked for binding atm)). We should probably pull this out into its own issue though (EDIT, see: #2271)

To get back on topic, I would like to try if we can do a similar thing with these Tuya remotes to prevent the battery drain. Maybe we can just have a "NoReportPowerConfiguration" cluster that prevents binding and reporting (and that'll be enough to prevent battery drain?).

@TheJulianJES
Copy link
Collaborator

Would one of you be willing to apply the changes from #2288 as a custom quirk?
This avoids the SKIP_CONFIGURATION which would prevent binding for all clusters, since we might want it for some.

Do note that to test this, you will have to download both the modified Tuya __init__.py file AND the ts000x.py file(s), put them in a folder in your custom quirks directory (e.g. tuya_remote_tests) AND in the ts000x.py file(s), change the following import line at the top from:

from zhaquirks.tuya import (

to:

from . (

Then, restart HA, re-pair oder re-configure the device. Then see if the battery drain continues.

All other changes regarding the remotes should be made in a future PR then.

@Fougues
Copy link

Fougues commented Oct 2, 2023

the buttons go up in action but there are systematically 2 actions which go up at the same time.
One empty and another for example 1_single.

Except that the automation sees only one, either the empty one or the other (1_single) when it sees the empty one then nothing happens.

so you can press the button and see nothing happen. it's quite random.
I couldn't find a way to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tuya Request/PR regarding a Tuya device
Projects
None yet
7 participants