Tuya Garage Door Opener with sensors

Your best bet would be to buy another sensor that is supported by HA and use that in a script on HA instead.

I personally use ZWave devices for a lot of things as they tend to work out of the box and dont really require any coding or flashing. Currently using an Aeotec Garage door opener but you’ve obviously already got this part working.

I’ve read a few people on here using ZWave tilt sensors that are around the $30 mark so could help with your problem once integrated as an automation in HA.

In localtuya, all switch works fine. But i have problem with garage opener witch sensors configuration.
Configure as a curtain or switch?

I’ve got the same issue here… doesn’t seem like anyone’s been able to get the SENSOR STATE of the Garage Door into Home Assistant yet???

@ezz9 can you confirm that using “localtuya” the state of the garage door opener is exposed to HomeAssistant (i.e. HA can see if garage is open or closed)?

I assume it does, given your previous comment on this post, suggested that is the problem you were looking to resolve.

Do you mind sharing the “localtuya” YAML syntax your using for your garage door opener? Many Thanks.

Hey @sebdoan
I used HACS to install the “localtuya” integration - and then configured with the main integration web interface. it was some trial and error finding the right setup, below is what’s working for me.
using version 3.0.1 at the moment, something in the updates something broke and I don’t have time to play so rolled back.


the only thing I’ve added to my config is in my customize.yaml

cover.garage_door:
    device_class: garage
1 Like

Thanks @ezz9 I’ve been spending the past 2 days trying to find an easy way to get the “Tuya Localkey”, turns out there’s no easy way.

For the benefit of others, here’s a HOW TO: get the “Tuya Localkey” based on the steps i took and adapted from https://github.com/codetheweb/tuyapi/blob/d30ef9a1b2c51a016b3a2864cbe0b226071482c3/docs/SETUP.md

Three High Level Steps I did: (I’ve hashed the values in my keys so you can see the rough format and length to expect)

1. Get your device added to Tuya app and get Virtual ID from app

  • Virtual ID from app: b######cb43a435330jyxu

2. Do the below steps on iot.tuya.com

  • Create a new account on iot.tuya.com and make sure you are logged in. Go to Cloud -> Project in the left nav drawer and click “Create”. After you’ve created a new project, click into it. The access ID and access key are equivalent to the API key and API secret values need in step 6.
    1. Access ID/Client ID: 8######ca6xyfib0075x
    2. Access Secret/Client Secret: 6######702b84adc886d0e2b55a227b2
  • Go to App -> App SDK -> Development in the nav drawer.
    1. Click “Create” and enter whatever you want for the package names (for the Android package name, you must enter a string beginning with com.).
  • Go to Cloud -> Project and click the project you created earlier. Then click “Link Device”. Click the “Link devices by Apps” tab, and click “Add Apps”. Check the app you just created and click “Ok”.
  • On the same page, click “API Group” on the left side. Change the status to Open for the following three API Groups by clicking “Apply” for each line, entering any reason, and clicking “OK”:
    1. “Authorization Management”,
    2. “Device Management”,
    3. “Device Control”,
    4. “User Management”,
    5. “Network Management”,
    6. “Data Service”
    7. “Device Statistics”.

3. Install and run uBuntu or any other Linux Distro

  • Open a Terminal and run the below commands
  • Sudo apt-get update
  • Sudo apt install npm
  • Sudo npm i @tuyapi/cli -g
  • Sudo tuya-cli wizard
    1. Access ID/Client ID: 8######ca6xyfib0075x
    2. Access Secret/Client Secret: 6######702b84adc886d0e2b55a227b2
    3. Virtual ID from app: b######cb43a435330jyxu
    4. Output:
      [ { name: ‘Smart Garage Door Opener’,
      id: ‘b######cb43a435330jyxu’,
      key: ‘f######b4675c4e7 } ]

With these steps you now have the Tuya local key: ‘f######b4675c4e7 to run with the “localtuya” custom integration.

Tomorrow or tonight i’ll give it a go with “localtuya” and update if it all goes well.

4 Likes

@ezz9 I’ve used localtuya v3.1.0 and can confirm it doesn’t work for me either. I’m using the configuration via the UI as you are doing.

I’ve found that localtuya v3.0.1-v3.0.3 work the same for me.
What works:

  1. State sensor of the Garage Door works
  2. Close command works

What doesn’t:

  1. Stop/Toggle command only works when is garage door is open
  2. Open command does nothing (works as a toggle command when garage door is open)

Given that localtuya accurately gives me the sensor state I’ve combined it with the standard tuya integration to create a template switch/cover that works exactly as I expected. It’s a lot of workarounds but in the end it works…

Why use the standard Tuya integration for the switch. Is it possible to configure the switch part in the Garage Opener. When I try I only get presented with the options concerning current. No on/off functions. Or have I missed something

I have been trying to use the same config but for me only the door sensor works, the actual open/closing doesnt work. I have to use the cloud tuya to open close (which doesnt have the door sensor) so its mixed bag at the moment and I was hoping someone could point me in the right direction. Tried all possible combinations of DPs and all versions, still no luck :frowning:

@fhratul what worked for me is I added a switch then added a binary sensor to that switch like below:

Step 1:image
Step 2: add binary sensor to detect door sensor state
step 3: Then i added a button on lovelace to detect garage state and toggle door like so:

type: button
entity: binary_sensor.doorcontact_state
show_state: true
name: Garage Door
tap_action:
  action: call-service
  service: switch.toggle
  service_data:
    entity_id: switch.garageswitch
2 Likes

I have the same issue, hopefully my solution works for you too. The way I get around it, is to combine the sensor from LAN with the button from the CLOUD via a “template switch”. This template switch will work as expected.

Here’s my config below:

switch:
  - platform: template
    switches:
      frontgatetemplate:
        value_template: '{{ is_state("cover.front_gate_tuya", "open") }}'
        turn_on:
          - condition: template
            value_template: '{{ is_state("cover.front_gate_tuya", "closed") }}'
          - service: switch.turn_on
            entity_id: switch.bfe76a6cb43a435330xxxx
          - delay: "00:00:10"
          - condition: template
            value_template: '{{ is_state("cover.front_gate_tuya", "closed") }}'
          - service: switch.turn_on
            entity_id: switch.bfe76a6cb43a435330xxxx
        turn_off:
          - condition: template
            value_template: '{{ is_state("cover.front_gate_tuya", "open") }}'
          - service: switch.turn_off
            entity_id: switch.bfe76a6cb43a435330xxxx
        friendly_name: 'Front Gate'

NOTE: you’ll see that i use conditions to check the sensor just before it executes the action to open or close. I also use a 10 second delay and re-execute the action to open, because sometimes the first request to open does not work.

1 Like

Anyone else had any luck integrating a garage door? I have just installed one and direct integration with local tuya isn’t working. Might have to try your suggestion

I had setup it as switch and created additional sensor to track the sensor state.

Switch entity is sending commands to device to initiate the action.

Sensor is tracking magnet value.

localtuya:
  - host: your_device_ip_address
    device_id: your_device_id
    local_key: your_local_key
    friendly_name: Garage Door
    protocol_version: "3.3"
    entities:
      - platform: switch
        friendly_name: Garage Door
        id: 1
        current: 7
        current_consumption: 101
        voltage: 102

sensor:
  - platform: template
    sensors:
      garage_door_is_open:
        unique_id: garage_door_is_open
        friendly_name: Garage Door Is Open
        value_template: "{{ state_attr('switch.garage_door','current_consumption') | float * 10 > 0 }}"

I added localtuya integration twice for one device id and one localkey, but with different entity id’s: 1 for binary sensor and 7 for switch
garage_door_integration
The entities look like

- type: entities
  entities:
    - binary_sensor.garage_door
    - switch.garage_switch

3 Likes

For those with problems geting the tuya localkey heres the easy way!!!

HOW TO - Get All Local Tuya Keys (ALL KEYS, SIMPLE, NO SOLDERING) - YouTube

then i added the switch by the tuya integration and the sensor through the local tuya integration

Can you please show your entity configuration, because I have still problems with the integration?

I’ve never been able to get Local Tuya to work.

The problem with sensors and the Tuya integration is that the Tuya integration doesn’t update the state right away. There’s therefore no point in bringing a Tuya sensor into HA; the delay makes it useless. (I did a test. I set up an automation within the Tuya app, to have the garage door sensor change the state of a Tuya plug, which does integrate as a device in HA. The problem is that the change in state takes some time to be visible in HA.

I have had more success with the Nortek garage door tilt sensors (Z-wave) which work perfectly.

I do have a secondary issue with the Tuya garage door controller, which is that HA treats it as a switch, but in the Tuya app it works as a momentary switch. I’ve tried automations in HA that detect the state change and then toggle the switch; but they don’t work right (door will stop in mid-lift or mid-fall). Going to try the momentary switch integration and see if that helps.

Hi,

I added a switch and a binary sensor like you in the screenshot but the sensor is not the signal from the sensor of the door opener its just a “virtual sensor” or similar, have you figured out a way to set the correct sensor state onto this binary sensor in HA?

Hello,
I have the same problem, I am unable to make the garage door show the status. Now it is no longer possible to use the old version of localtuya. Maybe there is already a way ?? maybe have you quit and are using something else?

Instead of relying on cloud based Tuya integration, go with localtuya, add your garage door device as switch and create a garage door cover using yaml. Please take a look at this: Tuya Garage Door Opener with sensors - #22 by fuatakgun

1 Like