Skip to main content

Tools to create a Domoticz plugin for local-tuya devices.

Project description

local-tuya-domoticz-tools

Tools to create a Domoticz plugin for local-tuya devices.

💡 The Domoticz version should be 2022.1 or higher.

Creating the plugin

To create a plugin, you will need to create 2 things.

Plugin metadata

This is the XML header that is used to populate the plugin creation page in Domoticz. You can create it using local_tuya_domoticz_tools.PluginMetadata.

Starting the device.

To start the plugin, you need to create the device and register the units.

Check local_tuya_domoticz_tools.plugin.plugin.OnStart for the function signature.

Units should be created using manager.register(...).

For a switch unit, it would look like:

from typing import Dict

from local_tuya import DeviceConfig, ProtocolConfig
from local_tuya_domoticz_tools import UnitManager, switch_unit

from my_device import SwitchState, SwitchDevice


def on_start(
    protocol_config: ProtocolConfig,
    _: Dict[str, str],
    manager: UnitManager[SwitchState],
) -> SwitchDevice:
    device = SwitchDevice(config=DeviceConfig(protocol=protocol_config))
    manager.register(
        switch_unit(
            id_=1,
            name="power",
            image=9,
            command_func=device.switch,
        ),
        lambda s: s.power,
    )
    return device

Units

Units represent a Domoticz device and is associated to a Domoticz hardware.

Manager

The role of the manager is to

  • create/remove units: register method
  • dispatch the commands from units: on_command method
  • update units state: update method

Unit types

For common units parameters, see the base.

Installing the plugin

You should provide a script that will be used to install the plugin. It would look like:

from local_tuya_domoticz_tools import install_plugin, PluginMetadata

def on_start(...):
    ...


if __name__ == "__main__":
    install_plugin(
        metadata=PluginMetadata(...),
        on_start=on_start,
        import_path="my_device.domoticz",
    )

💡 Domoticz path defaults to ~/domoticz a -p option can be passed to change that.

Filtering units

You can automatically add an option to the plugin to filter created units.

To enable it, you need to implement local_tuya_domoticz_tools.UnitId and add all unit IDs, then simply pass it to the install function. UnitManager.register will handle device deletion.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

local_tuya_domoticz_tools-1.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

local_tuya_domoticz_tools-1.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file local_tuya_domoticz_tools-1.1.0.tar.gz.

File metadata

  • Download URL: local_tuya_domoticz_tools-1.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for local_tuya_domoticz_tools-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7b0923d338152053736a6cad4b92e31625c9eaac2e8ec2f19fbb00d50424d8c2
MD5 b751d9c055bfe0c665258664131649cc
BLAKE2b-256 1ccab47d64fcb48e610e489cec51c3b32f782e3658c6f82e1c29def99d136713

See more details on using hashes here.

File details

Details for the file local_tuya_domoticz_tools-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for local_tuya_domoticz_tools-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5034c09edbcec7ca123246085799d498816de481abd443707d4970eeab85cddd
MD5 544681f929e730c13243c0835763a7ac
BLAKE2b-256 4ee8f4f120f83ca96b862bc9c2a7cff02b46dede3978b90cc3901d41289468e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page