Skip to content
sceeter89 edited this page Jun 21, 2015 · 9 revisions

Command-center is an application written in Python3, developed to support micro-automation of my apartment. It's designed to run on Raspberry Pi, but core application is platform agnostic, so with some changes to motors, and sensors it will work everywhere, where you can run python3. There are three terms that are crucial to application architecture, and use all over this wiki so they need to be well understood (plugins are described in detail in Architecture section):

  • Sensors - plugins that feed application with details about environment. Those might be used by motors to make proper decisions. By definition, sensors actions should not have any side effects.
  • Motors - plugins that execute some actions, basing on state coming from various sensors. For example, if temperature from thermometer sensor remains too high for too long, motor may turn air-conditioner on to lower it.
  • Core application - main application that user launches and that takes care of orchestrating communication between sensors and motors. It provides some basic information (called virtual sensors) about runtime conditions (such as unhandled exceptions, average loop duration, total loops counter)

To run application without any plugins, necessary prerequisites are:

Each plugin may introduce it's own dependencies, so please consult it's documentation about deployment and runtime dependencies.

Deploying

To start using Command Center you need to complete following steps:

  1. Clone repository to /etc/command_center (or choose other, arbitrary path)
  2. Ensure all application's requirements are met
  3. Remove or add any plugins you want and ensure plugins dependencies and configuration is fully performed
  4. If you want to start Command Center via supervisord then copy command_center.conf from ./supervisor/ to /etc/supervisor/conf.d/
  5. Start application either by running sudo python3 command_center.py in app's directory, or by reloading supervisor sudo supervisorctl reread sudo supervisorctl update

Architecture

As mentioned above, main components of application are: sensors and motors.

Sensors

Sensor - is basically anything that collects some information from environment. For instance it might be code that reads temperature from 1-wire thermometer or humidity from hygrometer. There are two types of sensors: custom and virtual. Custom sensors are pluggable via Yapsy library, and should be put in plugins/sensors directory. For details on developing your own sensor take a look at [Development](Developing custom plugins) page.

Below you will find list of all virtual sensors:

  • errors - value is list of all exceptions that occurred during current run. It's cleared every iteration. It contains tuples (plugin key, exception object) for every exception thrown.
  • now - contains date time of current loop start. It's identical for every motor.
  • disabled_plugins - list containing keys of all plugins that were disabled because of exceeded number of failures.
  • termination - if value is not None, means that system is about to shut down, and contains tuple in following format:
    (terminator's key, terminator's type name, reason string)
    
    If termination is user-initiated (i.e. user pressed Ctrl+C) then reason is set to: "User interruption", and terminator is set to None.
  • runtime - is a dictionary containing technical information about application. Following keys are available:
    • start_time - datetime object when application was launched
    • loop_counter - counter incremented with every loop of service
    • last_loop_time - duration of last iteration in seconds
    • average_loop_time - average loop duration in seconds
    • errors - dictionary where keys are plugin keys, and values are lists of thrown exceptions by those plugins

Motors

Motor - motor is a plugin, that basing on current sensors' state and own internal state, should perform some actions. For example when temperature remains too high, air conditioner might be turned on to drop it. Motors are loaded similarly to sensors - using Yapsy, and reside in plugins/motors directory. Unlikely to sensors, there are no virtual motors.

Clone this wiki locally