Button doesn't toggle switches/bulbs properly

I just bought a Tuya Zigbee button on Aliexpress that I'd like to use it for simply switching lights on or off. There are four buttons on it, and the lights that I'd like to toggle are so far a Sengled bulb in a lamp that's always powered and a Sonoff plug that a regular lamp is connected to. I'd like button 1 to turn the Sengled bulb on or off and for button 2 to turn the Sonoff plug on or off with just the "Push" command.

What I've found is that the button will only sometimes work as intended. For example, if the Sengled bulb is off and I push Button 1 on the physical button device, the Sengled bulb will sometimes turn on, but will more often turn on then off almost immediately. The same happens in reverse - if the Sengled bulb is on, Button 1 will turn the bulb off then on again. The same also happens with the Sonoff switch.

I'm thinking that this is an issue with the physical button device since when I go to the Button in the web interface and use the commands to "push" Button 1, it functions properly every time (if bulb is off, it turns on and stays on or if bulb is already on, it turns off and stays off).

Am I missing something here? I'm wondering if this is a result of having bought a cheap button instead of something from a more reputable brand and if so, if there's a workaround rather than shelling out more cash for a better button.


If it works when you "simulate" the push() command from the UI, my first guess is that the "real"/physical actions are sending different events than you suspect. Look at the "Logs" page (if you have descriptionText/info logging enabled for the device and the driver you're using follows Hubitat convention; some community drivers may not), or look at the "Events" tab on the device page (this is an authoritative source) to see what is actually happening when. Note that logs update in real time, whereas you will have to manually reload the "Events" page.

Then, I'd make sure that your automations line up with these actual events from the device. This will give you an idea of if/how you can modify your automations, or at least what the device behavior even is and if you can work around it somehow.

But that's all just a guess since we don't know any of the above. :smiley:

1 Like

I just checked the Events tab and it is indeed registering as two presses for some reason, one right after the other. Any suggestions on how to deal with that? That's incredibly frustrating.

Are you using a community driver? It's hard to say if it's a driver issue or a device problem, but the author might have more ideas on what would be helpful to figure that out.


The default type was Tuya Zigbee Scene Switch when I added it, so I left that there since it seemed to respond. Although if that's causing it then I guess I'll have to start learning how to get into community drivers.

If you are using a rule you could try to debounce the command. Something like this:

if (alreadyPressed == false) then
   toggle light
   alreadyPressed == true
   alreadyPressed == false delay 1 second 
end if

It isn't ideal but it might give you a short term workaround while you short out the root issue.

I tried using a different driver for the switch, the Tuya Scene Switch TS004F driver, but that did the same thing.

I am using Basic Rules for assigning the buttons, but I'm not sure how to implement that debouncing since I'm still very much a novice when it comes to anything more than adding devices. Would you be able to clarify how to actually do that workaround?

This doesn't match the name of any built-in driver, so I assume you are using custom/community code. I would suggest posting in the thread the author likely created for the release of this code to ask if this could be a driver or device issue.


I would still look for a better solution but this might help you in the short term. I don't have the Basic Rules app installed so I don't know if you can duplicate this there. If you install Rule Machine this is what your rule would look like:

Don't pay any attention to the pictures (light, truck, and crossed arrows). They are part of my device names and not part of the rule.

Let me see if I can give a quick overview.

Click on select trigger events. In my case I'm using an Inovelli switch as that's currently the only thing I have on this hub that shows up as a button device.

Next you need to setup a local variable before we create the actions. Below the trigger events and actions you should see a place to create local variables. Click on that and create a new Boolean variable with an initial value of false. I named this alreadyPressed.

Select Conditional Actions -> IF rule THEN -> New Condition

Select Variable from the list of conditions. Select your variable and false from the dropdowns and click done with this condition and click Done with IF rule THEN.

Select action to add -> Control Switches, Push Buttons -> Toggle switches -> select your switch.

Click Done with this action. Now add another action.

Select action to add -> Set Variable, Mode or File, Run Custom Action -> Set Variable -> alreadyPressed -> true

Click done and add another action.

Select action to add -> Set Variable, Mode or File, Run Custom Action -> Set Variable -> alreadyPressed -> false

Select the Delay? dropdown menu and select hrs:min:sec and enter 2 under seconds. Click Done.

Your rule should now look something like this.

Click on the END-IF button then the Done With Actions button. Finally click on Done and test your rule.

Sorry I didn't use circles and arrows but hopefully there's enough information here to help you setup a test.

1 Like

Welcome to Hubitat community, @IllFatedIPA !

A lot of Tuya devices are using non-standard Zigbee commands and are not supported out-of-the-box by hubs different than Tuya own hub. So you may need to use community written drivers for such devices.

Can you go to the device details page and post the data section? Should be something like this:

  • endpointId: 01
  • model: TS004F
  • application: 41
  • manufacturer: _TZ3000_xabckq1v

If your button is the same, you need to manually select the custom "Tuya Scene Switch TS004F" driver and then re-pair it again to HE. Simply switching the driver from the built-in "Tuya Zigbee Scene Switch" will not work, this device is very weird and requires very specific initialization that works only during the pairing process.

"Tuya Scene Switch TS004F" driver has built-in debouncing functionality, so you shouldn't need to implement custom complex debouncing rules. The debouncing rule proposed here should work, but in my opinion, it is overkill for such a simple thing as pressing a button event... Debouncing should be handled on Hub level (which unfortunately is not the case for this device) or at least on driver level.

If your device was identified as TS004F, follow these steps:

  1. Manually select "Tuya Scene Switch TS004F" driver from the device page
  2. Press "Remove device" button from the device page, click any button at the same time to make sure the device is awake.
  3. Pair the device again to HE. The correct driver "Tuya Scene Switch TS004F" should be selected automatically this time and the Tuya devices should be properly initialized.

If the device doesn't work properly again, enable the Debug logging from the Preferences section copy/paste the logs data and send it to me, hopefully we will find the reason for the malfunction.

1 Like

If my understanding of which menu is the drivers is correct, the Tuya Zigbee Scene Switch is a built in driver. I'm including a picture for reference of the menu under "Type" under Device Information. Ultimately the community driver for what appears to be the actual model of this button (just with a different front) still has the same issue, so I'll likely have to read through that whole topic to see if anyone has already solved this issue.

1 Like

So I think you've nailed it, @kkossev. I removed and repaired the button and while it didn't automatically select the Tuya Scene Switch TS004F driver, I changed it right after adding it and before touching any buttons on it and now it seems to be working properly. I've assigned lights to a few combinations of single/double clicks and holds to the various buttons and it seems to be responding properly now without shutting things off again. I'll take this as a learning experience and try to do more research on individual devices and their quirks before actually buying them, since I'll own up to ordering inexpensive Zigbee things because as of two weeks ago I assumed Zigbee was all one thing. It wasn't until a few days after placing those orders that I started reading up on that stuff.

@lairdknox, thank you for typing that all up - I'm hoping that could serve useful to someone that hasn't been able to find the right information yet. I'm very surprised at how helpful this community actually seems to be - I'm used to forums being rather hostile to newcomers and just being told that I "need to do more research" as if I hadn't already tried that before actually reaching out to people.


Hmm, you're right. Looks like they just didn't update the official device compatibility list with that information (or perhaps didn't want to for other reasons).

Looks like you got it working, though, so that's good!

I suppose there's the argument to be made that it wasn't compatible out of the box, at least for this particular device?

The built-in driver "Tuya Zigbee Scene Switch" has been written and tested with model TS0044.
About 6 months ago this model was silently replaced by all different manufacturers with a new model TS004F that has slightly different electronics inside and new firmware. However, both old and new models look the same and are sold as one and the same device. This is partially correct when used with the original Tuya gateway, as it recognizes the two models and switches the new TS004F model into a 'TS0044 compatible mode' - all this happens behind the scenes during the pairing process to Tuya zigbee gateway.

It's not just this device, a lot of other "Powered by Tuya" devices do not comply to the Zigbee standards (while they work perfectly with their own gateway). So it is always a risk purchasing these... The best and the safest approach is to stay with devices which are in the list of the officially supported devices by HE.

or this list:

@kkossev I will try to do that until I get some more ability to troubleshoot under my belt. Thank you for all of the help and the information!

We wait a few months and then get hostile! :rofl:

I knew there had to be a solution to be found. I don't use those devices so I had no background info. There are always a number of ways to accomplish a goal. Getting it paired correctly is obviously the best solution. Glad you got it working.