Skip to main content

Easy automation with MQTT and/or openHAB. Create home automation rules in python.

Project description

HABApp

Tests Status Documentation Status Updates PyPI - Python Version

PyPI Downloads Docker Image Version (latest by date) Docker Pulls

Easy automation with MQTT and/or openHAB

HABApp is a asyncio/multithread application that connects to an openhab instance and/or a MQTT broker. It is possible to create rules that listen to events from these instances and then react accordingly.

Goals

The goal of this application is to provide a simple way to create home automation rules in python. With full syntax highlighting and descriptive names it should almost never be required to look something up in the documentation

Documentation

The documentation can be found at here

Examples

MQTT Rule example

import datetime
import random

import HABApp
from HABApp.core.events import ValueUpdateEvent


class ExampleMqttTestRule(HABApp.Rule):
    def __init__(self):
        super().__init__()

        self.run.every(
            time=datetime.timedelta(seconds=60),
            interval=datetime.timedelta(seconds=30),
            callback=self.publish_rand_value
        )

        self.listen_event('test/test', self.topic_updated, ValueUpdateEvent)

    def publish_rand_value(self):
        print('test mqtt_publish')
        self.mqtt.publish('test/test', str(random.randint(0, 1000)))

    def topic_updated(self, event):
        assert isinstance(event, ValueUpdateEvent), type(event)
        print( f'mqtt topic "test/test" updated to {event.value}')


ExampleMqttTestRule()

Openhab rule example

import HABApp
from HABApp.core.events import ValueUpdateEvent, ValueChangeEvent
from HABApp.openhab.events import ItemStateEvent, ItemCommandEvent, ItemStateChangedEvent

class MyOpenhabRule(HABApp.Rule):

    def __init__(self):
        super().__init__()

        # Trigger on item updates
        self.listen_event( 'TestContact', self.item_state_update, ItemStateEvent)
        self.listen_event( 'TestDateTime', self.item_state_update, ValueUpdateEvent)

        # Trigger on item changes
        self.listen_event( 'TestDateTime', self.item_state_change, ItemStateChangedEvent)
        self.listen_event( 'TestSwitch', self.item_state_change, ValueChangeEvent)

        # Trigger on item commands
        self.listen_event( 'TestSwitch', self.item_command, ItemCommandEvent)

    def item_state_update(self, event):
        assert isinstance(event, ValueUpdateEvent)
        print( f'{event}')

    def item_state_change(self, event):
        assert isinstance(event, ValueChangeEvent)
        print( f'{event}')

        # interaction is available through self.openhab or self.oh
        self.openhab.send_command('TestItemCommand', 'ON')

    def item_command(self, event):
        assert isinstance(event, ItemCommandEvent)
        print( f'{event}')

        # interaction is available through self.openhab or self.oh
        self.oh.post_update('TestItemUpdate', 123)

MyOpenhabRule()

Changelog

0.20.2 (07.04.2021)

  • Added HABApp.util.functions with min/max
  • Reworked small parts of the file watcher
  • Doc improvements
  • Dependency updates

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

HABApp-0.30.0.RC1.tar.gz (94.6 kB view details)

Uploaded Source

Built Distribution

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

HABApp-0.30.0rc1-py3-none-any.whl (143.7 kB view details)

Uploaded Python 3

File details

Details for the file HABApp-0.30.0.RC1.tar.gz.

File metadata

  • Download URL: HABApp-0.30.0.RC1.tar.gz
  • Upload date:
  • Size: 94.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for HABApp-0.30.0.RC1.tar.gz
Algorithm Hash digest
SHA256 072d11973fdbb4f43df1a77c88351775a005d6f5283c47486dd4b16a5e6e9ccd
MD5 af29e88aff1cdaaab803a5003e55e4db
BLAKE2b-256 e9788f0a5ee9d9d163fd09e5c830a33c892fb1096c3cfcb4485391e70f58c492

See more details on using hashes here.

File details

Details for the file HABApp-0.30.0rc1-py3-none-any.whl.

File metadata

  • Download URL: HABApp-0.30.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 143.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for HABApp-0.30.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 0eef1279b96f49033a09d5a463d3da92777622d92b683a1a919767352b2ef9e2
MD5 ddc6cb297ec9750c41ee53564c0330cc
BLAKE2b-256 34f603f87cfbd30da85daebb8910b7f96c52cfa381397de10c970a7f64976a89

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