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]: State control vibration sensor #540

Open
1 of 3 tasks
goodsale opened this issue Feb 9, 2025 · 21 comments
Open
1 of 3 tasks

[Bug]: State control vibration sensor #540

goodsale opened this issue Feb 9, 2025 · 21 comments
Labels
bug Something isn't working

Comments

@goodsale
Copy link

goodsale commented Feb 9, 2025

LocalTuya Version

last

Home Assistant Version

last

Environment

  • Does the device work using the Home Assistant Tuya Cloud component?
  • Is this device connected to another local integration, including Home Assistant and any other tools?
  • The devices are within the same HA subnet, and they get discovered automatically when I add them

What happened?

I tried several vibration sensors from different brands, all compatible with TUYA but I always encountered the same problem.

The vibration sensor works correctly from the TUYA app and detects the vibration, turning the device back to OFF in the same app once the vibration has stopped.

When doing the inquiry from IOT, however, the value of the binary sensor always remains on "vibration" and makes control in Homeassistant impossible.

Is there a way for returning the status to off by checking subsequent changes?

{
  "result": {
    "properties": [
      {
        "code": "shock_state",
        "custom_name": "",
        "dp_id": 1,
        "time": 1739097130898,
        "type": "enum",
        "value": "vibration"
      },
      {
        "code": "battery_percentage",
        "custom_name": "",
        "dp_id": 4,
        "time": 1739094993096,
        "type": "value",
        "value": 100
      },
      {
        "code": "sensitivity",
        "custom_name": "",
        "dp_id": 6,
        "time": 1739008483977,
        "type": "value",
        "value": 71
      }
``` /

### Steps to reproduce.

.

### Relevant log output

```shell
.

Diagnostics information.

No response

@goodsale goodsale added the bug Something isn't working label Feb 9, 2025
@xZetsubou
Copy link
Owner

xZetsubou commented Feb 9, 2025

post the device diagnostics does the value never goes off on localtuya after it turning on? this also depends on device behavior you may want to enable debug for the device/interrogation and check what's device reporting when states goes on or off

@goodsale
Copy link
Author

goodsale commented Feb 9, 2025

I believe the device goes to sleep after a detection and does not communicate the next status (that is "drop").

I also noticed that if you change the "sensitivity" it is not sent to the device but is updated at the next event (when a new vibration is detected).

If you were able to "wake up" the device a few seconds after detecting the event, it could capture the correct state.

localtuya-vibration.json

@xZetsubou
Copy link
Owner

If that's the case how does the APP know when the device goes off, This is the first time I see low-power ZigBee device If that's the case then perhaps we can detect that using gateway? A look into logs is required If you enabled the debug for the sub-device then the debug for gateway will be enabled with name ends with /G as logger prefix prefer copy all logs,

Test when vibration is on and when it goes off wait for about a minute then copy logs.

@goodsale
Copy link
Author

goodsale commented Feb 9, 2025

There are other forums online with similar problems with vibrator devices.

It seems that there are some brands that after detecting the vibration return the value off, other brands do not.

By doing the query from TUYA IOT even during the vibration the value always remains on "vibrate".

log.log

@xZetsubou
Copy link
Owner

the logs is short device update in 22:46:12 and logs cut at 22:46:17 wait a minute or so at least after the device update as you can see the sub-device still online on the last payload If the device reported as offline when the vibrate is off then there might be a chance,

@goodsale
Copy link
Author

vibration events from Tuya App:

Image

Logs:

log 2025-02-10.log

@xZetsubou
Copy link
Owner

I don't think we can detect when it goes off by it states it seems the device always stays online, however is it possible it's by timer?
it seems the device whenever it detects it sends vibration on payload and it does that every time probably it the state doesn't change but maybe it reset? e.g. if it's goes ON then stays 15seconds without detect again it goes off?

@goodsale
Copy link
Author

These devices (vibration) have anomalous behavior and have also been analyzed in other discussions because they cause problems even when connected directly to HOMEASSISTANT and managed via mqtt.

As already mentioned, the device does not send the off signal after detecting the vibration.

If you manage to intercept the start of the vibration, you should force it back to "off" after a reasonable time.

From the tuya app the vibration is highlighted for a few seconds and then the device is highlighted off (3 - 4 sec).

Sometimes pid 1 "shock_state" switches to "drop" from "vibration" but this is rare, this PID almost always stays on "Vibration".

I have tried 3 devices from different brands and with all of them the behavior is the same.

Would it therefore be possible to intercept the vibration state and force the value "off" after 3-4 sec?

It would be the solution for all this type of devices.

Thank you!!

@xZetsubou
Copy link
Owner

xZetsubou commented Feb 12, 2025

Try to give binary_sensor_reset_state_interval branch with the reset timer feature on a shot.

@goodsale
Copy link
Author

Is it already possible to do a test in the "master" version?

Thanks!

@xZetsubou xZetsubou added the master/next-release Fixed in master branch, Will be ready in the next release label Feb 13, 2025
@goodsale
Copy link
Author

I tried the latest master
but everything seems the same as before.

I downloaded the master version from here, is that correct?

Image

@xZetsubou
Copy link
Owner

You need to reconfigure the binary sensor entity and set a reset timer.

@goodsale
Copy link
Author

here?
time in seconds?

Image

@xZetsubou
Copy link
Owner

No, that's the device configuration, not entity. Click submit until you reach the entity configuration that you want to set a reset timer for it it shoud exists at the bottom of the entity configuration

@goodsale
Copy link
Author

I don't have it in entity configuration

Image

@xZetsubou
Copy link
Owner

You may need to ensure that you installed master correctly, after downloading it copying custom_components into HA /config and replace all files should be enough, "HA Restarting is needed after"

Copy link

This issue was closed because it was resolved on the release: 2025.2.1

@github-actions github-actions bot added stale and removed master/next-release Fixed in master branch, Will be ready in the next release stale labels Feb 16, 2025
@goodsale
Copy link
Author

I tried the new version and now the field comes out.

with this configuration the sensor always remains off and no longer always on as before

I tried the new version and now the field comes out.

Image

@xZetsubou
Copy link
Owner

with this configuration the sensor always remains off and no longer always on as before

So basically how does this works if the device updated with the "on" value after 5 seconds it will return to "off" state, If the "on" value updated within the "5 seconds" the timer will be extended/reset to 5 seconds again.

@goodsale
Copy link
Author

there is one thing I don't understand....
If it automatically switches the status of the vibration sensor to off after the time entered (5 seconds), how do you switch it back to on if the status is not changed?

The status of the "vibrate" sensor always remains on "vibrate"... I think the new update brings it back to drop/off but then the sensor remains on "vibrate" and does not vary with the next change.

The timer logic is correct but it should find the state change somewhere else because in PID 1 the state almost never changes.

I think that's why it doesn't work.

@xZetsubou
Copy link
Owner

I think I may missed one thing which is that "status_update" only called if status changed since there is a condition for that.

how do you switch it back to on if the status is not changed?

It doesn't needs to change because the current logic rely on status update call not the state it self, so whenever the status_update is called from device this should trigger.

@xZetsubou xZetsubou reopened this Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants