Skip to main content

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.

Release files for micro-smart-hub 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micro-smart-hub 0.1.9
File Size Uploaded
micro_smart_hub-0.1.9.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for micro-smart-hub 0.1.9
File Interpreter ABI Platform
micro_smart_hub-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 32.8 kB

Release files / micro_smart_hub-0.1.9.tar.gz

Download URL micro_smart_hub-0.1.9.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
34f6bfb46e996a517e55f9f5d1c5d1f5684912cfbc533cd68b3125911a4fe112
BLAKE2b-256 checksum
How to use checksums
a2123081f3e03a8c6e7a2b51b7b0848b86cd7d028e57997c589a33c8729aa2b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / micro_smart_hub-0.1.9-py3-none-any.whl

Download URL micro_smart_hub-0.1.9-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ea6b4c7139fdc8a388cc16e2b91d32f5fee893a252d1289d0beaa16404018fb
BLAKE2b-256 checksum
How to use checksums
9a9e73dd52ebcca37ac48a6585ea2e3f72132cec9610a4b7ce888a8e68665651
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page