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
- Timer
Clock
Config:
["clock"]["location"] = <string>
- local time definition as defined in XXXXXXX
Object:
EventObject("clock", "now")
- Value - Current time: HH:MM
- Event - Every minutes
EventObject("clock", "day")
- Value - Current day:
Monday
,Tuesday
,Wednesday
,Thursday
,Friday
,Saturday
orSunday
- Event - Every day at 00:01
EventObject("clock", "sunset")
- Value - Current time for todays sunset: HH:MM
- Event - Every day at 00:01
EventObject("clock", "sunrise")
- Value - Current time for todays sunrise: HH:MM
- Event - Every day at 00:01
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
- Value - Countdown timer in seconds
- Set - Set new countdown value in seconds
- Event - Minutes left (represented in float).
"triggered"
When timer reaches 0 seconds
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)