Local tuya contact sensor

Hi All

I have setup Local Tuya and I have most things working.

I’m unable to get the contact sensor to work. Looks a little like this. https://www.bunnings.com.au/arlec-grid-connect-smart-contact-sensor_p0148575

Appears in tuya, I have the device ID and smart key, but I can’t seem to add it through the guided config.

Has anybody had success getting these sensors to work in Local Tuya?
Worked / Works fine in online Tuya.

Hi,

I have a wifi door sensor that is configured in tuya integration. But it’s not getting auto detected by local tuya integration and I am not able to integrate it manually via local tuya as well.

Please guide me, how can I integrate in local tuya integration.

Best Regards

Hello,

I managed to integrate the sensor locally. The problem I noticed is that the sensor only establishes a wireless connection when there is a contact change. After about 10 seconds it can no longer be pinged. You have to press the add button at the moment when it is pingable. It is best to switch contacts back and forth briefly. Unfortunately, the sensor is then displayed as offline after a short time. And it doesn’t always seem enough that he creates a change in the homa Assistant.

1 Like

how did you add the sensor locally, please share the yaml configuration…

I installed the localtuya plugin via the HACS and then got the data from the TUYA API key, ID. Then you also need the IP address of the sensor in your local network.

I’m new to Homa Assistant. If you can tell me how I can get the yaml data from the plugin, I’m sure I can help you further.

I have installed hacs and added local tuya. Also I have the api key, id and ip of the sensor. But I am not able to add the sensor to local tuya and the sensor goes offline very quickly within a second. So how have you added to local tuya. Please guide.

Put the Sensor on off on off on off an in this Moment you can the Sensor Ping. In this Moment you must finaly the configuration

1 Like

Tried but not getting detected by local tuya…

Any one knows how to add a contact sensor to local tuya using yaml… please help

I managed to get localtuya to discover the door sensors. It works like this:

  1. clear your browser cache
  2. Keep opening and closing the window/door constantly for the rest of the process (i will tell you when to stop)
  3. Reload the Home Assistant page and navigate to the localtuya Integration.
  4. Click Configure and add device. If you are still opening and closing your window/door your sensor will be visible there and can be selected
  5. If you are using the cloud api, all data like local key will be filled in. If not, fill them in (you can pause while filling in, but before clicking add, you have to continue opening and closing the window/door)
  6. Click add and select “binary sensor” as device type.
  7. You can stop now opening and closing the window.
  8. You can select now if you have a door or window and give your sensor a name
  9. Now you should be able to select an entity card type and thats it.
2 Likes

Thanks for the detailed steps.

From the last half an hour I have been trying to do as mentioned in the steps. But the sensor just doesn’t appear in local tuya.

How fast are you opening and closing the sensor.

i even tried this in configuration.yaml but sadly it doesn’t work either.

localtuya:
  - host: 192.168.1.99
    device_id: hdbdbd7433gs
    local_key: absgdg543
    friendly_name: Tuya Device
    protocol_version: "3.3"
    scan_interval: 1
    entities:
      - platform: binary_sensor
        friendly_name: Sensor_Status
        id: 1
        device_class: power
        state_on: "on" # Optional
        state_off: "off" # Optional

i dont understand what am i doing wrong. :frowning:

I open and close se tensor every 3 - 5 Seconds because only in this time the season connect to your clan and is available. The connection must be enabled when the sensor have wlan.

But connect a tuna contact sensor via local tuna ist not good. The sensor is offline every time because when the sensor have nothing to do he has no active plan so home assistant shows the sensor as offline.

ezgif.com-gif-maker (1)
This is how I am opening and closing

This is the pace i was using either. Does you Tuya App get triggered when you do this?

Yes it triggers if I do it very slowly… by doing slowly it almost impossible to add it via local tuya. It seems my only option left is to add it via configuration.yaml but I gave no idea about the correct entries

If there are not triggers even in the Tuya App, then local Tuya won’t help. Try new batteries and removing from tuya app and re-adding the sensor

I know this is an old post but it really helped me out.
Couldn’t get the contact Sensor to integrate until I tried simply opening and closing the switch when I clicked submit. Then it magically accepted the device and recognized the integration.
That said I’m completely lost so far as how to make it notify me.
I do see in the integration that the contact says “False” when open. And then quickly looses connection as the device shuts down to conserve power.
So not knowing yaml I have a challenge ahead. But thanks for the tip here.

I’m happy i could help you out.
Tuya contact sensors have the problem to go offline and change the state to unavailable after going offline.
I fixed it with some hotfix. For every tuya contact sensor I created a helper (Go to settings=>Integrations=>Helpers and add an input_boolean/switch). Now go to settings=>automations and create for every contact sensor one automation as follows:
Start with an empty automation
Trigger:
State:

  • Entity: (your tuya contact sensor: binary_sensor.entitynamehere)
  • To: false
    Actions:
    Call a service: Input_Boolean.turn_off
    Intity: (your helper entity)

Now add another automation but with Trigger when “To” is set to “true” and Call a service “Input_boolean.turn_on”. Other Settings are set equal to the first automation.

Now you have an input_boolean that acts as the tuya sensor should act. Please note, that when the tuya sensor is opened or closed, it first connects to the wifi and then reports the status. It may take a few seconds to react and trigger the automations.

3 Likes

I know this is an old thread, and I just got my sensor working in LocalTuya, but is there a way to get the battery percentage as well?

@Draganis appreciate your guidance, following your guide I managed to get the contact sensors working. Also the work-around using helper functions to persist the state of the sensor works like a charm, thanks a lot!

1 Like