Skip to main content

A small smart hub building blocks package

Project description

Micro Smart Hub

Micro Smart Hub is a flexible and lightweight smart home automation platform designed for managing various devices and automations. It is easy to extend and configure, making it ideal for a wide range of home automation tasks.

Table of Contents

  1. Features
  2. Installation
  3. Running the Scheduler Application
  4. Developing with Micro Smart Hub
  5. Extending with New Automations
  6. Creating New Devices
  7. Configuration
  8. Examples
  9. License

Features

  • Supports custom automations and devices
  • Asynchronous scheduling of tasks
  • Configuration via YAML files
  • Lightweight and portable

Installation

Micro Smart Hub is available as a Python package and can be installed using pip:

pip install microsmarthub

Running the Scheduler Application

To run the Micro Smart Hub scheduler, use the micro-smart-server command-line application. This application reads configuration files and manages the execution of scheduled tasks.

Usage

micro-smart-server [options]

Options

  • -s, --schedule: Path to the schedule YAML file. Default is ./schedule.yaml.
  • -d, --devices: Directories containing device modules. Default is the current directory.
  • -a, --automations: Directories containing automation modules. Default is the current directory.
  • -c, --config: Path to the configuration YAML file. Default is ./config.yaml.

Example

'''bash micro-smart-server -s ./schedule.yaml -d ./devices ./extra_devices -a ./automations ./extra_automations -c ./config.yaml '''

Developing with Micro Smart Hub

Extending with New Automations

To create a new automation, inherit from the Automation class and implement the run method:

from micro_smart_hub.registry import register_class
from micro_smart_hub.automation import Automation


@register_class
class MyAutomation(Automation):
    def run(self, action, parameters, devices):
        print(f"Running {action} with parameters {parameters} on devices {devices}")

Creating New Devices

To create a new device, inherit from the MicroDevice class and implement the required methods:

from micro_smart_hub.registry import register_class
from micro_smart_hub.device import MicroDevice
import requests


@register_class
class MyIoTSwitch(IoTSwitch):
    def __init__(self, definition=None):
        super().__init__(definition)
        self.device_id = self.definition.get("device_id", "default_id")

    def load_info(self):
        response = requests.get(f"http://{self.device_id}/info")
        self.info = response.json().get('device', {})

    def load_state(self):
        response = requests.get(f"http://{self.device_id}/state")
        self.status = response.json().get('status', {})

    @property
    def on(self):
        return self._on

    @on.setter
    def on(self, value):
        if value:
            requests.post(f"http://{self.device_id}/turn_on")
        else:
            requests.post(f"http://{self.device_id}/turn_off")
        self._on = value

    def off(self):
        self.on = False

Configuration

Configuration is done via YAML files. Define your schedule, devices, and automations in separate YAML files.

Schedule Example

FakeAutomation:
  schedule:
    monday:
      - time: 6       # Without minutes (6:00)
        action: on
      - time: 18.30   # With minutes
        action: off
  devices:
    - FakeSwitch

Irrigation:
  schedule:
    monday:
      - time: "6:05"    # With minutes but as a string
        action: on
      - time: 18      # Without minutes (18:00)
        action: off
  devices:
    - Irrigation_Pump

Device Configuration Example (config.yaml)

Define your devices and their parameters in a config.yaml file. Here is an example configuration:

Pump:
  class: SwitchBox
  parameters:
    url: 192.168.0.3

Garden Light:
  class: SwitchBox
  parameters:
    url: 192.168.0.197      

SmartIrrigation:
  class: Irrigation
  parameters:
    latitude: 12.24541322
    longitude: 32.32243421

# Pump: An instance of SwitchBox with a specific IP address.
# Garden Light: Another SwitchBox with a different IP.
# SmartIrrigation: An instance of Irrigation with specific geolocation parameters.

Examples

Check out the examples directory for more detailed examples of how to set up and run automations and devices.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Thanks to all contributors and users for their support and feedback.

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

micro_smart_hub-0.1.6.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

micro_smart_hub-0.1.6-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file micro_smart_hub-0.1.6.tar.gz.

File metadata

  • Download URL: micro_smart_hub-0.1.6.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for micro_smart_hub-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a7757ad309feb1bd609fab22d2f4699bc137b80c659d0d71cdd1f9695d1b21f4
MD5 41380304fc7a8233ee478a28c64e8a22
BLAKE2b-256 53bf265e78d680cd30a89679a9d3d349382409066d8b438b669db39397eca256

See more details on using hashes here.

File details

Details for the file micro_smart_hub-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for micro_smart_hub-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 757d3486595500930e6d3134220123dbdd83351edb0b8afcf1e4dcf78d858090
MD5 c1c12f238e3425f3a6c4f82ce5b16af8
BLAKE2b-256 eba0a6ecf8a94f3f571aa6cd8cc51330f029032cf58ac5b9b64451e4634bf2da

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