LEDVANCE integration - this is how to do it as per 08/22

With the work of very talented peope, it is now possible to control LEDVANCE lights LOCALLY.
A video in DANISH:

What to do?

  1. Install Python on your machine
  2. Add modules requests and pycryptodome
  3. Get the package from FlagX: GitHub - FlagX/ha-ledvance-tuya-resync-localkey: pyscript for homeassistant to resync local keys from private tuya api
  4. Fix print-local-keys.py with your LEDVANCE username and password
  5. Run print-local-keys.py
  6. Add the lights to local tuya with the local keys and IPā€™s shown
  7. You should also go through the FlagXā€™ explanation of how to add the ha-ledvance-tuya-resync-localkey
4 Likes

Hi
Thanks for the info, I am currently trying to get my LEDVANCE lightbulbs added to Local Tuya
I tried running the script(print-local-keys.py)
I am getting an InvalidAuthentication exception, I am 100% sure the username and password is the same as the LEDVANCE app ones, am I missing something?
I even created a new account to make sure there is no confusion with the LEDVANCE tuya credentials and the smart life ones I also have.
Am I correct if I understand that the Tuya details in the const.py file remain unchanged?
Thank you in advance for any help!
UPDATE:
It looks like the latest version of the LEDVANCE app uses different credentials than the old version
I installed an older version and had to register again there with the same email account.
Now when I run the script I get ā€˜NoneTypeā€™ object is not iterable, because the response is empty(I couldnā€™t add any of my devices on the old app)

This looks like bad news for using theses devices with LocalTuya in the future.

I think maybe @Flag can chime in here, and spread some knowledge, I havenā€™t had any issues.
I have updated the sync_tuya_keys.py with my user/pass, I set the TUYA_COUNTRY_CODE in const.py and updated my user / pass in print-local-keys.py

I think the NoneType object error you get, is because you do not have any devices registered on your account.
It could be possible that Ledvance enforces a newer API version on newer accounts.

Iā€™ve new Ledvance Wifi bulbs and added them successfully to the LDV APP on my iPhone. Now I would like to integrate them into HA via localTuya.

Iā€™ve installed the python modules on my mac, inserted the my used login data from the APP and tried the python script.

Unfortunately Iā€™m also running into the mentioned InvalidAuthentication exception. Are there any new ideas to fix this?

It seems to be quite difficult to get these local keys of the devices.

Not sure if it has relevance, but what region are they in?

I have changed the country code to 49 (germany) in the const.py. Germany is also the region in the LVD APP.

This is the exception message, hope it helps:

Traceback (most recent call last):
  File "/Users/macbook2/Downloads/ha-ledvance-tuya-resync-localkey-main/print-local-keys.py", line 5, in <module>
    api.login()
  File "/Users/macbook2/Downloads/ha-ledvance-tuya-resync-localkey-main/pyscript_modules/tuya/api.py", line 231, in login
    login_info = self._api({"action": "tuya.m.user.email.password.login"}, payload, requires_sid=False, do_not_relogin=True)
  File "/Users/macbook2/Downloads/ha-ledvance-tuya-resync-localkey-main/pyscript_modules/tuya/api.py", line 168, in _api
    result = self._handle(self.session.post(TUYA_ENDPOINT, params=params, data=data, headers=headers).json())
  File "/Users/macbook2/Downloads/ha-ledvance-tuya-resync-localkey-main/pyscript_modules/tuya/api.py", line 215, in _handle
    raise InvalidAuthentication
pyscript_modules.tuya.exceptions.InvalidAuthentication

It is not the same as the exception when the login data is wrong.


Iā€™m getting this error and canā€™t find any way to change it. Changed region and country code in the code but nothing. Does any other method still work?

Hey @DrGadorcha, I ran into the same error. However, I solved it just by updating in pyscript_modules/tuya/const.py file, the TUYA_ENDPOINT variable, the value https://a1.tuyaeu.com/api.json , if you are living in some Europe region that value is just fine, but If you are living in the States or South America, you should change the previous value to https://a1.tuyaus.com/api.json Notice it that you need only to update a1.tuyaus.com subdomain, and thatā€™s all.

Just added my new under cabinet light successfully using local tuya. Unfortunately, the only thing I can do is turn it on/off, thereā€™s neither an option to change brightness nor the color temperature. Did I do something wrong or is it simply not supported yet?
Via the ledvance app I can change brightness and color temperature easily.

It is not all stuff that can be controlled unfortunately, Iā€™ve had some success with experimenting with the different fields in the tuya integration.

Hey,
do I need to create a cron-task to update the keys automatically?

Hi @zu3st-de Unless you reset them all the time, the keys donā€™t change :slight_smile:

Hello! Iā€™m stuck at inserting my password into the python script. The script looks different from the one shown on the YouTube video, probably because itā€™s a newer version. I tried two places, lines 21 and 22, and the line 28. Neither worked (unless there was some other problem). The first one gave the error message ā€œModuleNotFoundError: No module named ā€˜Cryptoā€™ā€ (I have pycryptodome installed), the second one gave ā€œSyntaxError: invalid imaginary literalā€. Hereā€™s the current version of the script:

#!/usr/bin/env python3

import getpass
from typing import Tuple

from pyscript_modules.tuya.api import TuyaAPI
from pyscript_modules.tuya.exceptions import InvalidAuthentication

def get_login() -> Tuple[str, str]:
    def ask_until_ok(fn) -> str:
        while True:
            try:
                return fn()
            except KeyboardInterrupt as e:
                print("Aborted.")
                raise
            except:
                pass
            print()
    return (
        ask_until_ok(lambda: input("Please put your Tuya/Ledvance username: ")),
        ask_until_ok(lambda: getpass.getpass("Please put your Tuya/Ledvance password: "))
    )

def main():
    username, password = get_login()

    api = TuyaAPI(username, password)
    try:
        api.login()
    except InvalidAuthentication:
        print("Invalid authentication.")
        exit(1)
    except Exception as e:
        print(f"Unexpected error: {e}")

    print('---------------------------')
    for group in api.groups():
        for dev in api.devices(group['groupId']):
            print(f'device name:\t{dev.name}')
            print(f'device id:\t{dev.id}')
            print(f'local key:\t{dev.localKey}')
            print('---------------------------')
    input("Press Enter to continue...")

if __name__ == "__main__":
    main()
2 Likes

I got the above problem solved, and also a bunch of others, so now I have my Ledvance Sun@Home led spots installed and working in Home Assistant :slightly_smiling_face:. The effort must have taken a few months away from the length of my life, though. Iā€™m still recovering mentallyā€¦ I hope Home Assistant at some stage becomes available as a normal program, so that thereā€™s no more need to learn to use containers. After trying so many different things, I actually donā€™t know exactly how I ultimately got the container to work. Of course it would be nice to get Ledvance lights to work with Home Assistant without all the other tricks that it currently takes. Anyway, itā€™s great that some people have seen the trouble to make it work for the rest of us. Thanks fribse for the helpful video!

1 Like

I found an instruction on Reddit to fill in certain brightness and colour temperature values when adding lights as entities to Home Assistant. The suggested value for brightness is 22 and for colour temperature 23. That helped me, and now both settings work on my installation. The thread is here:

The actual values come from this page:

2 Likes

Hi, Iā€™m quite new to HA.
One important thing is that I want to add my Ledvance devices (RGB strips and switching sockets) to HA.
When I perform the steps above and disconnect the devices from the original cloud, I assume that they are not useable in the original ledvnace app anymore, right?

Background is that Iā€™m uncertain on the handling of these devices via HA. Which means Iā€™m uncertain on the WAF (woman acceptance factor). And if the WAF is too low I cannot use HA to control the devices. :wink:

1 Like

Hi ThomasHo
Well, LEDVANCE is a cointoss, they refuse to open up integration, so you could try this.
If you get it to work, itā€™s solid, if it doesnā€™t work it could be because of firmware updates of the bulbs.
I have three LEDVANCE running here, no issues what so ever.

Heya,
Iā€™m currently trying to get this working.
The print_local_keys script gives me these values:
device name, device id, local key
Whereas the local tuya integrations is asking for:
Client ID, Secret, User ID

Does anybody know the correct mapping ? Which value goes where ?

Nevermind, in case anyoneā€™s interested: I ended up using this PR of the local tuya component which works quite good. I hope the PR will eventually make it into the official integration.

4 Likes