Happy to assist through this, enjoy your garage door
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
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.
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:
- Value (False)
- Value (0)
- Value (False)
- Value (20)
- 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!
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.
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 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
first define a localtuya switch following this: Tuya Garage Door Opener with sensors - #33 by fuatakgun
after setting up localtuya switch, you need to setup additional sensor.
when you are done with sensor and switch, it is time to setup garage door cover as templating.
All of them captured in linked post.
Sidenote:
Not exactly Tuya, but ESPHome (so 100% local). And not exactly for users here who have bought Tuya already…
But as an alternative, I ran into this product page the other day. This company would pre-flash generic ESP8266 products for ESPHome / Tasmota / Homekit.
Garage Door Opener for ESPHome | athom
And the items in the kit / package seem complete… with cable management clips and all.
Find it interesting, and figured I should share.
Good share, ATOM is tasmotizing tuya devices and sell them. If tuya users have esp based devices, they can also flash and use this esp based solution.
Thanks for the response.
I did set up a switch as you instructed but I’m not getting the script done.
In scripts.yaml file, I’m doing the following as per the tutorial.
alias: garage_door_close
sequence:
- type: turn_off
entity_id: switch.garage_door
domain: switch
- type: turn_on
entity_id: switch.garage_door
domain: switch
mode: single
alias: garage_door_open
It is showing me error at “alias: garage_door_open”.
Can you please help?
Hey there, there are 2 different scripts, not one.
Please double read the main post and try to create 2 different scripts as garage_door_close and garage_door_open
It doesn’t seem to work.
I’m using Tuya official HA integration. Not localtuya. Is that a possible issue?
Ah yes, my solution is about localtuya, i am not a fan of official Tuya integration, still using old version of it
Your a fucking legend @danioj
Thanks a lot for the explanation and debug logic you applied. i was able to do the same for my device, got it working, felt like a genius.
Thanks !
Hi Dhaval, looks like you’ve gotten some info already but here’s a clearer run down of my setup. This is only for localtuya, I don’t use Tuya cloud integration at all so not sure how would configure it for that.
By the way, in the latest localtuya (v3.3.0 at time of writing) device class can now be set when configuring the entity so no need to customise in HA.
To open and close I add an entity with switch type.
Next step, configure the entity as below (I’m using DP1 to open/close which is ID 1), give it a name and ignore the other 3 fields. (The ID may vary between different controllers but is likely to be the first one and should be true/false value)
Next add another entity of binary_sensor platform which we’ll use to detect door open/closed
Configure the entity as below, I’m using 101 but again may vary. It should have a true/false value.
You can now change the device class in localtuya as I mentioned so set this entity to garage_door and it will display properly in HA
Once that’s all done, you should have all the entities you need to use in the cover template I’m using above.
Hope this helps.
Hi There @bamzero I have a Tuya Garage Door opener and I have set it up with Tuya Local. I have followed your instructions above and I cant get the switch to work. I have 4 IDs to choose from and have tried all of them. The only one that seems to get any response is IDs 105.
However, when I select the switch the garage door wont open but I get a notification from the Tuya Smart Life App “Your garage door has been opened for 10 minutes” but the garage door doesn’t actually open? Can anyone help with this setup?
Yeh yours is completely different to mine so I’m not sure how much help I can be, but at a guess I’d say 105 is your open/close sensor (like I used as a binary_sensor above). If HA is flipping it as a switch, it could explain why Smart Life is warning you the door is open.
If you can, try tuyadebug and manually open and close your door so you can see what values you get back during the operation. Just remember to exit Smart Life app completely as keeping it open will usually block localtuya.
I would have thought the first ID would be most likely to trigger the opener but it seems each model varies quite a bit.