4.7 KiB
+++
title = "Core"
weight = 6
date = "2018-08-06T20:43:20.000Z"
lastmodifierdisplayname = "Christoffer Martinsson"
lastmodifieremail = "christoffer.martinsson@mildef.com"
+++
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 funtional 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 manageing 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,Tuseday,Wednesday,Thursday,Friday,SaturdayorSunday - 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")
self.day = EventObject("clock", "day")
self.sunset = EventObject("clock", "sunset")
self.sunrise = EventObject("clock", "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", "<NAME>)
<NAME> - Name reference for timer
- Value - Countdown timer in seconds
- Set - Set new countdown value in seconds
- Event -
"triggered"When timer reches 0 seconds
Example:
class Config(ConfigObject):
def setup(self):
# -------------------------------------------------------------------------
# Create event objects
# -------------------------------------------------------------------------
self.timer_test = EventObject("timer", "test")
def process_event(self):
# -------------------------------------------------------------------------
# Create workflows
# -------------------------------------------------------------------------
if self.timer_sink.event == "triggered":
self.zwave_kitchen_sink_light.set("false")
if self.zwave_kitchen_motion.event == "true":
self.timer_sink.set(120)