pyscript for homeassistant to resync local keys from private tuya api
This repository includes
- A script
print-local-keys.py
to print out local keys for your Ledvance devices (They must be already registered in the Ledvance app) which can be used in the LocalTuya integration for Home Assistant - Setup via Pyscript Integration to automatically resync local keys
Install the dependency and run the script (python 3):
pip install pycryptodome
python print-local-keys.py
On Windows you may have to install the requests
module before:
pip install requests
If you have many devices and reset them sometimes by accident like me, you can create a service for resyncing the local keys. (New local keys are generated if you reset/re-register your devices).
- Pyscript Integration
- Set
allow_all_imports
andhass_is_global
to true. (Described here) - Ledvance account with devices configured
- Replace placeholders in
pyscript\sync_tuya_keys.py
with your Ledvance account credentials. - Copy
pyscript_modules
andpyscript
to your Home Assistant config directory. - In your Home Assistant dashboard should be now under
Developer tools
-->Services
a service calledPyscript Python scripting: synctuyakeys
that you can call. (You may have to restart before) - (If you want Log output, you need to change the log level to INFO or use jupyter)
Credits for the python Tuya API client go to: https://github.com/rgsilva/homeassistant-positivo I also extracted the keys/secrets by following his guide: https://blog.rgsilva.com/reverse-engineering-positivos-smart-home-app/