Trigger an Automation on an event even when the state doesn’t change

I have a Tuya Scene select switch that reports its state as an enum click, double or long based on how the switches are pressed.
The status of the switches are currently reported as State in an HA Sensor.
However if Button 1 is pressed the sensor shows its state as click. If after a few minutes the Button 1 is pressed again, the sensor still shows the state as click. i.e. the state doesn’t change.
So how do I Trigger an Automation when the state doesn’t change.
There is clearly some event bring triggered when the Button is clicked, because within the Tuya app it can trigger a scene on every button click regardless of what the previous state of the button was. How can that be achieved in HA.

Event Trigger

Your challenge is to discover the event that is produced when the button is pressed.

  1. Use Developer Tools > Events
  2. Enter * in Listen to events
  3. Click Start Listening
  4. Press Button 1
  5. Confirm an event is displayed
  6. Quickly click Stop Listening (otherwise other events will also be displayed)

You can configure the Event Trigger using the information shown in the event.

Thats the thing. I dont think any event is triggered when the state value does not change. I’ve tried the method above and can see an event logged only when the state changes between click and press. But no event gets triggered when the button is clicked and then clicked again.

Then it may be due to a limitation of the underlying integration.

Some other integrations produce an event for certain activities such as button press/hold/release.

This switch is using which integration?

Its a Tuya scene switch and I am using the Smartlife integration as the Tuya integration doesn’t support this switch.

just curious, what device is it? (model or link to amazon or something)?

you might try this integration instead of using the cloud based tuya integration:

this one seems to have more coverage. also it gets all the events locally so if it’s firing an event, it may be more likely to surface… and if not, the developer of it is in this community and active so might fix it for you.

I am using the Smartlife integration which is the successor the Tuya cloud integration.

This is the switch
.
CORUI Tuya WiFi Smart Wireless Switch Push Button Controller 2Gang Smart Controller Automation Scenario Smart Home Gadget
https://a.aliexpress.com/_Eyu9Arx

Support for the " wxkg" was added to the Smartlife integration. But that is only updating the sensors if the actual state changes. However if the same button is clicked again, the second click isn’t picked up as a state change.

Then the situation is how I described it two months ago; it’s a limitation of the integration.

Given that the Smartlife integration is currently in beta, contact TuYa and explain how it currently fails to meet your needs to detect a second press of the same button.

+1 to @123

you still might also try localtuya. it can live side by side with the cloud integration. i have them both running and there are some times i prefer one versus the other. most of the time the local one works better for me, and exposes more details of the device.

There might be a way to fix this. Create an automation which sets the state of your button back to “none” on ANY state change after a tiny (100ms) delay.
You might need to play around with the delay settings, but at least you’ll be able to receive consecutive duplicate states.

I can’t take any credit for this logic. Z2MQTT works in exactly the same way to handle events sent to HA.

Except that Z2M is the source of truth for the sensor’s state value; it has exclusive control.

What you’re proposing attempts to emulate the behavior without being the actual source of truth which is the Smartlife integration. In other words, you’re proposing to overwrite the sensor’s true value.

The first challenge is that Home Assistant provides no native service call for setting a sensor’s state value (because a sensor is supposed to be read-only; only its underlying integration has write privileges). There’s a python_script available that overwrites an entity’s state value but the new value is not permanent; it’s replaced by the next update performed by the underlying integration or a restart.

Given that the Smartlife integration is in beta, this is an ideal time for brucemiranda to request proper support for button events (including consecutive identical button events). Ideally it should use an event entity to model button events but a compromise is to use a sensor whose value indicates the actual button event (press/hold/release) or what Z2M does with a sensor (report button event momentarily then immediately return to an idle state by reporting an empty string).

You’re right, my bad. Could have sworn there was a service call which essentially does the same thing as changing the state in the Dev tools

I have tried the trick when I set the Sensor of Button 1 to None/Off after I have processed my Automation.
The trouble is that on any button press all the states of the sensors are updated from the cloud. So when I click Button 2, Button 1’s state is updated to the value held on the cloud and the Button 1 Automation fires again even when Button 2 is clicked.

I need to try and catch the event the button is raising to the cloud, rather than processing the response from the cloud, if that makes sense.

@armedad what is the direct github repo for the localtuya you are using.
Also where can I see what device ids are supported by localtuya because none of the Tuya integrations seemed to support this scene switch wxkg
Even Smartlife had to be amended to introduce support for it. But the support has been introduced with the buttons defined as sensors that are simply updating their state from the tuya cloud.

The one that indicates the feature you want isn’t supported?

Seems cheaper, in time and effort, to simply buy a device that supports double-clicks.

The issue is not the lack of a double click. Its the lack of the ability to sense the same event that happens one after another. So the same issue happens with double click as well.
Once double click is sensed, you wont get another event for the next double click.

If you review the Blueprints Exchange section of the forum, you’ll see that there are several remote-control devices (buttons) that don’t explicitly report a ‘double-click’ event, yet there are blueprints for them that support virtual double-click events. They rely on the ability to detect two consecutive identical events occurring within a short time span.

The device you bought not only doesn’t support an explicit ‘double-click’ event, it doesn’t produce discernable consecutive identical events that can be interpreted as a virtual double-click event.

If this device is as new as you have said it is then you are, unfortunately, one of the first to discover it doesn’t support double-click in any form (until TuYa enhances their Smartlife integration).

The inescapable conclusion is that you bought a ~$7 device that falls short of your needs and can’t be made to fulfill them without the manufacturer’s involvement.

Good luck with whatever you choose to do next.

Looks like you have 3 options:

  • Raise an issue on the Smartlife integration and wait until this is fixed & merged in.
  • Flash the device with LibreTuya/OpenBeken (or whatever the kids are calling it these days).
  • Chuck it in a drawer and forget about it. Use it as a $7 learning experience to do your research before buying any smart device.