localtuya
localtuya copied to clipboard
Cloud API for Tuya OEM API for Ledvance and other generic Tuya vendors + usability improvements
This PR adds support for Tuya's OEM cloud API (the same API used by Tuya-derived mobile apps), in particular LEDVANCE, as their client ID and secret are known, but also any other vendor by entering their client id/secret.
The cloud config flow was redesigned to prompt the user for the cloud type first:
- Tuya IoT Platform (i.e. the existing cloud support)
- Tuya OEM LEDVANCE - needs only email and password for the LEDVANCE mobile app
- Tuya OEM generic - needs email, password and vendor client id/secret
- No cloud
The OEM implementation supports:
- Fetching the local key
- Fetching the name
- Deriving a meaningful product name such as "LEDVANCE Light Source" based on the Tuya category returned by the API
In addition there are some usability improvements too:
- Use the category returned by the IoT/OEM API to determine the default platform when adding an entity
- Use Tuya's documented DPs as defaults for the light platform
- Use the device name as the default entity name
This means you can now add a light simply by clicking through the dialogs as the defaults are what you want (or very close to what you want). It can be easily extended to cover more entity types.
Other changes:
- Config is now version 3, version 1/2 will be migrated
- Refactored the cloud API a bit to allow for more isolation and different implementations
- Some config steps now use the new (as of April 2022) HA show menu step - which actually made some translations work
- Tried to adjust the existing it and pt-BR translations to reflect the changes - might need a native speaker to have a look
- Updated the README.md and info.md + some new screenshots
- Removed the "username" field for cloud configuration
- It had default value "localtuya" and set the name of the integration - had nothing to do with the cloud
- The name of the integration when added is now fixed to "Local Tuya" (can be edited later)
Credits: https://github.com/FlagX/ha-ledvance-tuya-resync-localkey whose code was used as a basis for a more cleaned up integrated version.
Any news on this?
hi, this looks quite cool. is there any statement from the maintainers yet regarding whether they'd want to merge this? I can imagine that the included secrets might be problematic.
Works like as it should for me! Like a charm! But took me, as beginner and noob, one day to understand git and manual installation in HA. Should be merged ...
bump?
I'd love to have this merged. It's working perfectly
Rebased on master, now identical to v5.2.1 + my patches.
Rebased on master, now identical to v5.2.1 + my patches.
Any way to test this as an normal user? I have to integrate 4 ceiling fans from ledvance and would love to test it.
Thank you so much for this, works perfect for my Ledvance devices.
Bump -, works great 👍
bump - after couple of hours to install it (it is not clear what is the best way to do it) it worked. Would be nice to include in upstream
Rebased onto latest @rospogrigio master. For anyone who wants to use this -- https://github.com/avataar/localtuya/tree/oem-cloud-ledvance-5.2.1 is another branch that is based on the latest official release (v5.2.1).
In order to use this without waiting for merging (which seems likely will never happen, I have no idea why) you can simply get the custom_components/localtuya directory and copy it into the custom_components directory of your HA (just like with any other manually installed custom integration).
Disclaimer: this code upgrades the configuration structure of the integration so downgrading to the non-patched version may not be as simple as just getting the non-patched version. In any case, deleting the integration and adding it again should resolve any issues if you're trying to revert back to the non-patched version.
Bump Thank you so much!
Can anybody help me retrieve the local keys for my ledvance devices. i´m running the python script that you posted (here) but receives invalid account ID or password.
What is the email and password i should use? i´ve tried the Tuya IoT credentials, the ledvance app, the tuya app etc. nothing works. Am I missing something...?
Can anybody help me retrieve the local keys for my ledvance devices. i´m running the python script that you posted (here) but receives invalid account ID or password.
What is the email and password i should use? i´ve tried the Tuya IoT credentials, the ledvance app, the tuya app etc. nothing works. Am I missing something...?
You should use the email and password for the Ledvance app. Check out the region parameter too (-r) as it defaults to "eu" and you may need a different value there.
usage: list_tuya_devices.py [-h] [-r {eu,us,cn,in}] [-v {ledvance,generic}] [-c CLIENT_ID] [-s SECRET] email password
I run it like list_tuya_devices.py <email> <password>
or list_tuya_devices.py -r eu <email> <password>
and it works either way. If I give the wrong region I get an error "Session has expired, please log in again". If I give the wrong email or password I get "Incorrect account ID or password" so if you're getting that, it might be a different issue than the region. Double check the Ledvance credentials and/or try changing your Ledvance password.
Can anybody help me retrieve the local keys for my ledvance devices. i´m running the python script that you posted (here) but receives invalid account ID or password. What is the email and password i should use? i´ve tried the Tuya IoT credentials, the ledvance app, the tuya app etc. nothing works. Am I missing something...?
You should use the email and password for the Ledvance app. Check out the region parameter too (-r) as it defaults to "eu" and you may need a different value there.
usage: list_tuya_devices.py [-h] [-r {eu,us,cn,in}] [-v {ledvance,generic}] [-c CLIENT_ID] [-s SECRET] email password
I run it like
list_tuya_devices.py <email> <password>
orlist_tuya_devices.py -r eu <email> <password>
and it works either way. If I give the wrong region I get an error "Session has expired, please log in again". If I give the wrong email or password I get "Incorrect account ID or password" so if you're getting that, it might be a different issue than the region. Double check the Ledvance credentials and/or try changing your Ledvance password.
that worked! thanks! and for future reference, i used the Ledvance mobile app credentials.
However, the integration only returns 6 DPs where as the light should have like 20 since the device has 2 seperate lights, with color, brightness etc. I can controll all of this in the Ledvance app but guess i´ll just have to wait and hope they some day integrate it to HA or Tuya... It was worth a shot tho! I´ll leave the Smart Things integration for now
There is only a small issue, but I'll guess its Edge related. Everything fine on App. It saves so much work, esp. for LEDVance
@rospogrigio can we please get a merge here? Do you need something additionally?
Hi @avataar, it looks like @rospogrigio doesn't have time to maintain this, wouldn't it be best if you took over on this, it looks like you know what you are doing?
Nice Work, was playing around with 2 Clouds at the same time (LedVance + Tuya) - Problem here the Devices of the first added cloud getting unaviable after adding the second Cloud Account.
And: the Branch without Version Branding 5.2.1 throwing and unexcepted error on Adding Tuya Cloud but works with Ledvance. The 5.2.1 works on both.