Tuya Garage Door Opener with sensors

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

Thanks for reply, I Find Your post before and try do this like You bro but i have a problem. I’m new in home assistant.

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

This part work for me and i have switch but i have a problem with this part

  • sensor
    garage_door_is_open:
    unique_id: garage_door_is_open
    friendly_name: Garage Door Is Open
    value_template: ‘{{ states.switch.garage_door.attributes.current_consumption | float * 10 > 0 }}’

When i pase it into configuration yaml I’ve got error in line sensor

Maybe i should add something

1 Like

When you click on your switch and access detail view, can you see the attribute as ‘current_consumption’? And does it change based on your magnetic garage door sensor?

Moreover, you can only have one main sensor line and all sensor definitions should go under below it. Either check your formatting in YAML file or check if there is another sensor section.

Update: apparently i had an issue of missing line there, updated it, it should work now.

Thank a lot !! It works !!! :smiley: Is it possilbe to make it like garage door button which show open or close icon depend on sensor status ?

2 Likes

UPDATE: I have gathered everything into one post here

  • Setting up localtuya and sensors in configuration.yaml
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 }}"
  • setting up cover in configuration.yaml
cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: "{{ states.switch.garage_door.attributes.current_consumption | float * 10 > 0 }}"
        open_cover:
          service: script.garage_door_open
        close_cover:
          service: script.garage_door_close
  • setting up scripts created from UI
alias: garage_door_close
sequence:
  - type: turn_off
    entity_id: switch.garage_door
    domain: switch
mode: single
alias: garage_door_open
sequence:
  - type: turn_on
    entity_id: switch.garage_door
    domain: switch
mode: single
2 Likes

Thank a lot !

sequence:
  - type: turn_on
    device_id: xxx
    entity_id: switch.duza_brama_garazowa
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 700
  - type: turn_off
    device_id: xxx
    entity_id: switch.duza_brama_garazowa
    domain: switch
mode: single
alias: Duża brama garażowa
icon: hass:garage

Something like this ?? I was wondering if the script has to be one that turns off the switch after a while or not

Maybe this is enough

sequence:
  - type: turn_on
    device_id: xxx
    entity_id: switch.duza_brama_garazowa
    domain: switch
mode: single
alias: Duża brama garażowa
icon: hass:garage

updated my previous post

Thanks ! Can I make one script with toggle it should do the same job ?

I would not do like that because you might have issues with out of sync between tuya cloud and local states. So, I wanted to be sure that, it is always doing sth correct and intentional.

Thank you very much for your help, now it works as I always wanted, I think it will be useful not only for me. Thank you for your patience because I am a beginner and I asked a lot of simple questions :smiley: :smiley: :smiley:

Happy to assist through this, enjoy your garage door :slight_smile:

I have never been able to get LocalTuya to work. Mainly because the developer site where you are supposed to get the keys keeps changing, and none of the guides out there has been updated to the latest changes on the developer site, meaning I never get my keys :rofl:

I am using this, it is working so far without any issues. tuyapi/SETUP.md at c0a1526379461d6cc0378d06c6f6a32c90c47208 · codetheweb/tuyapi · GitHub

Finally got my garage door opener working with current version of localtuya (3.2.2)

I have the Wofea controller. It only has 3 DPs, 1, 7 and 101.
1 and 101 are both false when closed, true when open and 7 is always 0.

In localtuya integration UI I added DP 1 as a switch, ignoring current etc.
I added DP 101 as a binary sensor for open/close detection. While I could probably just use DP 1, when I toggle the switch it will momentarily switch back until it realises it is still in the open or closed position so the icon in HA UI does as well. Cleaner to use 101.

In my configuration.yaml I added the following cover template:

cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >-
          {% if is_state('binary_sensor.garage_door_status','on') %}
            Open
          {% else %}
            Closed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id:  switch.garage_door_switch
        close_cover:
          service: switch.turn_off
          data:
            entity_id:  switch.garage_door_switch
        stop_cover:
          service: switch.toggle
          data:
            entity_id:  switch.garage_door_switch
        icon_template: >-
          {% if is_state('binary_sensor.garage_door_status','on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

I don’t use the switch or binary sensor in the UI but I did customise the sensor as a garage_door so would show as Open or Closed instead of on or off anyway.

garage_door_button garage_door_panel

2 Likes

I found this thread by luck after I posted a new thread about this very issue. I too have a Tuya based garage door device with an attached open / close sensor.

I can can get this thing integrated with both localtuya and tuyalocal but the problem is maintained. Because the integration sees this as a switch (with no state) then all it is useful for is opening and closing the door while you’re in front of it.

Ive tried the methods posted above but what I have concluded is all this does is try to work around the integration seeing this as a switch and manage the status in Lovelace it does not actually grab the state of the sensor at all.

I tested this by just using my dumb remote or the physical button on the garage door unit itself. Each time, the door opens as expected but no state update is reflected in HA.

Unless I have something wrong? Hopefully the new Tuya Integration v2 (especially when they release local device support) will help.

Strike my previous post. I have solved it. I am now actually capturing the state of the attached sensor to my unit. The work done in this thread helped allot. Especially @anon63427907 posts which were the basis of me solving this.

I had to use Developer Tools to identify which attribute which carried the value which indicated whether the door was open or closed was mapped to.

current: false
current_consumption: 0
voltage: 0
friendly_name: Garage Control
icon: hass:garage

It was obvious from his simple algorithm in his previous post that he was testing the value of “current_consumption”. For the life of me I couldn’t figure out why my value wasn’t changing when the door opened or closed. That was because my device was slightly different.

So I added the device again and stepped through pragmatically. When adding the device it was clear I had 5 attributes:

  1. Value (False)
  2. Value (0)
  3. Value (False)
  4. Value (20)
  5. Value (0)

It took me a while to figure out that what you are doing when setting up the integration is mapping these device values to the static fields:

Current
Current Consumption
Voltage

It doesn’t mean that the values contain those things, you are just mapping the device variables to them so you can see (and subsequently test) the value.

Through the developer tools I established that variable 3. changed to ‘0.1’ when the reed switch was disconnected and change to ‘0’ when it was connected. Excellent. That made the code in the above post make more sense. When that variable is 0 door is closed. When that variable is 0.1 the door is open. I tested this by controlling the door using non HA means (IR remote and Tuya App) and the variables changed along with the state of the reed switch.

I ended up mapping my device like this:

Current → 1. Value (False)
Current Consumption → 3. Value (False)
Voltage 1. Value (False)

So for my device 1. is the switch and 2. is the reed switch value indicating open and closed.

So I used the code in the above post as a basis to create a sensor attached to that 2. variable and test as it changed from 0.1 to 0 to indicate open and closed state. I didn’t like the unfriendly value that the code above spat out so I modified it to give me a friendlier value:

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

All is now well. It doesn’t matter whether the door is opened or controlled manually or via HA I know have a live (offline as its via Local Tuya) state of the door and a switch that changes along with manual control as well.

Awesome! :slight_smile:

EDIT: as I test more, it appears that there is a combination of values that will allow me to determine states “Opening” and “Closing” too along with just “Open” and “Closed”. Will post once I have tested thoroughly.

1 Like

Please share opening and closing, i could not find it from DP values, interested in this.

By the way, reasoning for third voltage and current is, i had just copied my existing templates from other devices without fixing them :slight_smile: or shortly laziness. Still curious about your findings on opening and closing, please share

Hi Bamzero,

Can you please explain this in a bit more detail? I have this Wofea garage door opener. I have it integrated in HA using localtuya but the garage door status is not working right.

In Tuya (smartlife) app, it shows the correct status of the door but in HA it doesn’t.

Can you please help by explaining your solution in a bit more detail? I don’t really know what you mean by “In localtuya integration UI I added DP 1 as a switch”.

Thanks,
Dhaval