gpajot / local-tuya

Interface to Tuya devices over LAN.
MIT License
1 stars 0 forks source link

working without plugin? #58

Closed ricorico94 closed 1 year ago

ricorico94 commented 1 year ago

Hi, I don't feel comfortable with creating a plugin by myself despite your explanations. Did you ever create a plugin yourself for Domoticz or not ? And if we don't go for a plugin, is there an easier way to use your scripts to control Tuya devices in local mode ?

br, Ricorico94

gpajot commented 1 year ago

Hello,

Sorry for the late reply... You can check existing plugins I made here: https://github.com/gpajot/local-tuya#examples

If you want to map the device state values you can use something like this to print values while playing with the device using the remote to see changes as they are registered by the device:

import asyncio

from local_tuya import Device, DeviceConfig, ProtocolConfig, State, Values

class PrintState(State):
    @classmethod
    def load(cls, values: Values) -> State:
        print(values)
        return cls()

async def main():
    async with Device(
        DeviceConfig(
            ProtocolConfig(
                id_="xxx",
                address="xxx",
                key=b"xxx",
            ),
        ),
        PrintState.load,
    ):
        await asyncio.sleep(1000)

if __name__ == "__main__":
    asyncio.run(main())

The main goal if this library is to have a robust connection maintained and be able to control the device while supporting external control such as with the remote. To just send one-of commands to the device you might be better off using other tools such as tinytuya.

Thanks, Gabriel