Core

HAASP Core engine that transport all event to and from all other modules. It also deliver configuration to all modules. ! This module is required to have a functional installation of HAASP !

Installation

Docker image:
cmtec/haasp_core

Pip: Make sure you have python3, git and pip installed
pip install -U git+https://git.cmtec.se/haasp/libhaasp.git pip install -U git+https://git.cmtec.se/haasp/haasp_core.git

Usage

The config file is located at ~/.haasp/haasp_config.py
This configuration is the essential part of managing HAASP.

Empty Template

from libhaasp import EventObject, ConfigObject

class Config(ConfigObject):

    def config(self):
        config = {}
        # -------------------------------------------------------------------------
        # Configure modules 
        # -------------------------------------------------------------------------
        
  return config

    
    def setup(self):
        # -------------------------------------------------------------------------
        # Create event objects
        # -------------------------------------------------------------------------


    def process_event(self):
        # ------------------------------------------------------------------------- 
        # Create workflows 
        # -------------------------------------------------------------------------

Please see the configuration chapter for more example how to use the configuration file

Built in applications

The core module has two built in application modules:

Clock

Config:

["clock"]["location"] = <string> - local time definition as defined in XXXXXXX

Object:

EventObject("clock", "now")

EventObject("clock", "day")

EventObject("clock", "sunset")

EventObject("clock", "sunrise")

Example:

class Config(ConfigObject):

    def config(self):
        config = {}
        # -------------------------------------------------------------------------
        # Configure modules 
        # -------------------------------------------------------------------------
        config["clock"] = {}
        config["clock"]["location"] = "copenhagen"
        
        return config


    def setup(self):
        # -------------------------------------------------------------------------
        # Create event objects 
        # -------------------------------------------------------------------------
        self.clock = EventObject("clock", "now", name="self.clock")
        self.day = EventObject("clock", "day", name="self.day")
        self.sunset = EventObject("clock", "sunset", name="self.sunset")
        self.sunrise = EventObject("clock", "sunrise", name="self.sunrise") 
    
 def process_event(self):
        # ------------------------------------------------------------------------- 
        # Create workflows 
        # -------------------------------------------------------------------------
        if self.clock.event == "06:30" or self.clock.event == self.sunset.value:
            self.zwave_livingroom_window_light.set("true")

        if self.clock.event == "23:00" or self.clock.event == self.sunrise.value:
            self.zwave_livingroom_window_light.set("false")

Timer

Object:

EventObject("timer", "<REF>", name="<NAME>")

<REF> - Unique reference for timer
<NAME> - Logging name for timer

Example:

class Config(ConfigObject):


    def setup(self):
        # -------------------------------------------------------------------------
        # Create event objects 
        # -------------------------------------------------------------------------
     self.timer_test = EventObject("timer", "test", name="self.timer_test")
 
 def process_event(self):
        # ------------------------------------------------------------------------- 
        # Create workflows 
        # -------------------------------------------------------------------------
        if self.timer_sink.event == "triggered":
            <something>.set("false")
        
        if <some_event>:
            self.timer_sink.set(120)