Skip to main content

Python Scenario Automation contains a library to interface with Scenario IFSEI Classic for home automation.

Project description

Scenario IFSEI Interface

Tests codecov PyPI version Documentation Status

Python Scenario Automation contains a library to interface with Scenario IFSEI Classic for home automation. This library was designed and tested with IFSEI version: Ver 04.12.15 - NS 00.00.00 - DS 05.02.

Table of Contents

Installation

To install the package, use pip, which is the package installer for Python:

pip install pyscenario

This command will download and install the latest version of pyscenario from the Python Package Index (PyPI).

Usage

To use the package, first import the necessary modules:

import pyscenario
from pyscenario.ifsei import IFSEI
from pyscenario.network import NetworkConfiguration, Protocol

To connect to an IFSEI device, you need to create an IFSEI instance with the appropriate network configuration. Here’s how you can do that:

# Create a NetworkConfiguration object with the IP address, and port numbers for 
# command and data channels, and protocol
network_configuration = NetworkConfiguration("192.168.1.20", 28000, 23000, Protocol.TCP)

# Create an IFSEI instance with the network configuration
ifsei = IFSEI(network_config=network_configuration)

# Load devices from a device configuration file
ifsei.load_devices("device_config.yaml")

# Connect to the IFSEI device asynchronously
await ifsei.async_connect()

Supported devices

The IFSEI.load_devices() function will populate three entities: zones, lights, and shades (covers). Each of these entities represents a different type of device that can be managed by the IFSEI interface. All entities are optional, but they provide a structure to the configuration and management of the home automation system.

Device Manager supports only Light and Shade/Cover devices.

The file config_schema.py contains the valid schema for the yaml file. This file gets validated using Voluptuous lib.

Devices config file

To properly load and interact with devices, they must be defined in a YAML configuration file. Without this configuration, the integration will have no devices to interact with. The default file name is scenario_device_config.yaml.

Example of device config file:

# Zone config
zones:
  - id: 1
    name: Area de Servico
  - id: 2
    name: Banho

# Lights config
lights:
  - id: 1
    name: Bancada
    zone: 2
    isRGB: false
    address:
      - name: w
        module: 4
        channel: 5
        isDimmeable: false
  - id: 2
    name: Sanca
    zone: 1
    isRGB: false
    address:
      - name: w
        module: 3
        channel: 8
        isDimmeable: false
# Shades config
shades:
  - id: 1
    name: Cortina
    zone: 2
    address1: "0002"
    address2: "0003"
    address3: "0004"
  - id: 2
    name: Persiana LD
    zone: 1
    address1: "0005"
    address2: "0006"
    address3: "0007"

Light

Light devices support both dimmable (isDimmeable: bool) and RGB (isRGB: bool) configurations. Each light should have at least one address, usually the w for the white channel. RGB lights should also have r, g, and b addresses.

The update callback should support **kwargs with the following parameters:

  • IFSEI_ATTR_AVAILABLE: availability of the device
  • IFSEI_ATTR_BRIGHTNESS: white channel with value from 0 (off) to 100 (max brightness)
  • IFSEI_ATTR_RED: red channel with value from 0 (off) to 100 (max brightness)
  • IFSEI_ATTR_GREEN: green channel with value from 0 (off) to 100 (max brightness)
  • IFSEI_ATTR_BLUE: blue channel with value from 0 (off) to 100 (max brightness)
def light_update_callback(self, **kwargs: Any):
    brightness = kwargs.pop(IFSEI_ATTR_BRIGHTNESS, None)
    available = kwargs.pop(IFSEI_ATTR_AVAILABLE, None)
    red = kwargs.pop(IFSEI_ATTR_RED, None)
    green = kwargs.pop(IFSEI_ATTR_GREEN, None)
    blue = kwargs.pop(IFSEI_ATTR_BLUE, None)
    print(f"Light Update - Brightness: {brightness}, Available: {available}, Red: {red}, Green: {green}, Blue: {blue}")

Shades / Covers

Shade devices typically have three addresses. The first corresponds to the up command, the second to stop, and the third to down.

The update callback should support **kwargs with the following parameters:

  • IFSEI_ATTR_AVAILABLE: Availability of the device
  • IFSEI_ATTR_COMMAND: Command for the device (IFSEI_COVER_DOWN, IFSEI_COVER_UP, or IFSEI_COVER_STOP)
  • IFSEI_ATTR_STATE: State of the scene (IFSEI_ATTR_SCENE_ACTIVE or IFSEI_ATTR_SCENE_INACTIVE)
def shade_update_callback(self, **kwargs: Any):
    available = kwargs.pop(IFSEI_ATTR_AVAILABLE, None)
    command = kwargs.pop(IFSEI_ATTR_COMMAND, None)
    state = kwargs.pop(IFSEI_ATTR_STATE, None)
    print(f"Shade Update - Available: {available}, Command: {command}, State: {state}")

Message reception and processing

The IFSEI class creates two queues: one for receiving messages and another for sending messages. These queues are also used by the telnet client to process incoming and outgoing messages. All messages are processed by the IFSEI class, and the IFSEITelnetClient puts and gets messages from these queues.

It is possible to set a delay between messages to be sent. This can be done by calling the set_send_delay function with a time in seconds:

ifsei.set_send_delay(0.2)

Connection handling

After the first connection is established, the IFSEI instance will try to reconnect in a separate monitoring thread if the connection is lost. This thread is created after the on_connection_lost is called.

Upon the first connection, the device should respond with *IFSEION, indicating that it is available. All devices in the device manager with registered callbacks will be notified.

To close the connection and stop all read, send, and processing tasks, call:

await ifsei.async_close()

Device updates

It is possible to add subscribers to each device so that they can be notified when specific state changes occur. Device availability and state status are sent to the callback when received by the IFSEI instance.

Example of adding a subscriber:

light.add_subscriber(self.update_callback)

def async_update_callback(self, **kwargs: Any):
  """Update callback."""
  brightness = kwargs.pop(IFSEI_ATTR_BRIGHTNESS, None)
  available = kwargs.pop(IFSEI_ATTR_AVAILABLE, None)
  red = kwargs.pop(IFSEI_ATTR_RED, None)
  green = kwargs.pop(IFSEI_ATTR_GREEN, None)
  blue = kwargs.pop(IFSEI_ATTR_BLUE, None)

  if available is not None:
      self._attr_available = available
      _LOGGER.debug("Set device %s availability to %s", self.name, available)

Example

This library is used in Home Assistant custom integration for Scenario Automation.

Contributing

If you feel you can contribute to the project, please read the contribution guide at CONTRIBUTING.

Contact

Carlos Mazzei (carlos.mazzei@gmail.com)

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

pyscenario-0.1.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

pyscenario-0.1.3-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file pyscenario-0.1.3.tar.gz.

File metadata

  • Download URL: pyscenario-0.1.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pyscenario-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f3b0a427890469352dacd314ab34216c8655dc82facff4cb70f255974b19a2e2
MD5 76382e2b50bb3017ce73d5f8d66dca6f
BLAKE2b-256 9ef9ada559898483a061f1241c1d27961116f3c3dd6db336981b2ec234f04ee0

See more details on using hashes here.

File details

Details for the file pyscenario-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyscenario-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for pyscenario-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0db4a36b15b2641ee5faff8f9e663cdfb110ebe86c38a9b4c930d80502c030b0
MD5 a2474a603f1d48fdb66f9a0f5c364488
BLAKE2b-256 bce56bd3bf426051cdbed6c9faf4b08ce373fb80fed2c3e3528eb51ae70adf1e

See more details on using hashes here.

Supported by

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