Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

THC Getting started

Andreas Drollinger edited this page Jun 12, 2016 · 16 revisions

THC - Getting started

This document provides instructions for the installation and configuration of THC on your computer.

Requirements

THC requires that Tcl 8.5 or above is installed on the target system. The Tk extension is not required to run THC.

To log device states and to plot graphs either the standalone RRD tools or the RRD package for Tcl needs to be installed.

To use the mail alert module, the Unix 'mail' command needs to be available.

Installing THC

The full THC package should be stored at a location from where the THC program can be executed. On Unix derived systems this may be /opt, but it can also be another location. The THC main program (bin/thc.tcl) needs to be executable (e.g. Run on Unix: chmod 775 bin/thc.tcl).

On Unix derived systems THC can be configured as service to start it automatically each time the system boots.

See also: THC installation on a Raspberry

Configuring THC

THC requires the configuration file config.tcl that is usually stored inside the THC main directory. This configuration file declares devices and automation tasks (jobs). Configuration file template and example files are placed in the THC main directory. They provide good starting points to write a customized configuration file. Read also the THC-Basics documentation to get some basics about the way to handle device states and events. This information is required for the declaration of jobs.

  • Heartbeat definition: The heartbeat defines the update interval in milliseconds. The default update interval is 1000ms.
 set HeartBeatMS 1000
  • Specify a log file and a log level (level: 0 - very detailed log, 3 - log of important messages, see also DefineLog)
 DefineLog 1 "/var/thc/thc_server.log" 1
  • Start the HTTP web server by providing the IP port to use
 thc_Web::Start 8086
  • If you use a z-Way/Razberry controller, define the z-Way server access IP port (see thc_zWay::Init)
 thc_zWay::Init "http://localhost:8083"
 # Virtual devices
 	DefineDevice Surveillance,state \
 	    -name Surveillance -group Scenes -type switch \
 	    -get {thc_Virtual "Surveillance"} \
 	    -set {thc_Virtual "Surveillance"}

 # Z-Way devices
 DefineDevice MotionSalon,state  -get {thc_zWay "SensorBinary 12"} -sticky 1
 DefineDevice Sirene,state       -get {thc_zWay "SwitchBinary 16.0"} \
                                 -set {thc_zWay "SwitchBinary 16.0"}
 DefineDevice LightSalon,state   -get {thc_zWay "SwitchBinary 8.1"} \
                                 -set {thc_zWay "SwitchBinary 8.1"}

 # OpenWeatherMap devices
 DefineDevice ChauxDeFonds,temp \
        -name Bern -group Environment -format "%sC" -range {-30 50} -update 10m \
        -get {thc_OpenWeatherMap {"Bern,ch" "temp"}}

 # OpenWeatherMap devices
 DefineDevice ChauxDeFonds,chx_hum \
        -name "Humidity Chaux-de-Fonds" -group Environment -format "%s%%" -update 10m \
        -get {thc_MeteoSwiss {"CDF" "humidity"}}
  • Automation tasks/jobs definitions (see DefineJob)
 DefineJob -tag Surv -description "Alarm detection" \
           -condition {$Event(Alarm,state)==1} {
    Set {Sirene,state LightSalon,state} 1
    Log "Alarm on" 1

    DefineJob -tag SirenOff -description "Stop the alarm siren" -time +3m {
       Set Sirene,state 0
       Log "Alarm siren stopped" 1
    }

    DefineJob -tag LightOff -description "Switch off the alarm lights" -time +45m {
       Set LightSalon,state 0
       Log "Alarm lights turned off" 1
    }

Please refer to the documentation of the different extension modules to get information about module specific configurations.

Start THC

Before you run THC make sure that the THC main program is executable (on Unix like systems) and that the log directory exists (e.g. /var/thc). If the Tcl interpreter executable is named 'tclsh' THC can be directly launched with the following command :

 <THC_ROOT_DIR>/bin/thc.tcl [Options]

Otherwise mention in the command line explicitly the Tcl interpreter command :

 <TclInterpreter> <THC_ROOT_DIR>/bin/thc.tcl [Options]

The options have to be pairs of THC internal variable names prefixed with '-' and the corresponding variable initialization values. The following variables may be changed :

Description
DebugScript Allows defining a debug script file that will be executed after loading the modules, but before the configuration file is executed.
ConfigFile Configuration file. The default configuration file is 'config.tcl' that is stored inside the THC root directory.

Example :

 tclsh thc.tcl -DebugScript HtcDebug.tcl

Go test THC!

If you started in your configuration file a web server you can now open in your preferred web browser the THC website. The default web interface should be compatible with any newer browsers. To point your browser to the THC website, enter as URL :

 http://<ThcInstallHost>:<ThcPort>