Skip to content

THC Getting started

Andreas Drollinger edited this page Nov 9, 2019 · 21 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.

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). An example configuration file is placed in the THC main directory. It provides a good starting point 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.
 thc::DefineHeartBeat 1000 MS
  • Specify a log file and a log level (level: 0 - very detailed log, 3 - log of important messages, see also thc::DefineLog)
 thc::DefineLog 1 "/var/thc/thc_server.log" 1
  • Start the HTTP web server by providing the TCP/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
 thc::DefineDevice Surveillance,state \
        -name Surveillance -group Scenes -type switch \
        -get {thc_Virtual "Surveillance"} \
        -set {thc_Virtual "Surveillance"}

 # Z-Way devices
 thc::DefineDevice MotionLiving,state  -get {thc_zWay "SensorBinary 12"} -sticky 1
 thc::DefineDevice Sirene,state       -get {thc_zWay "SwitchBinary 16.0"} \
                                      -set {thc_zWay "SwitchBinary 16.0"}
 thc::DefineDevice LightLiving,state   -get {thc_zWay "SwitchBinary 8.1"} \
                                      -set {thc_zWay "SwitchBinary 8.1"}

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

 # OpenWeatherMap devices
 thc::DefineDevice ChauxDeFonds,chx_hum \
        -name "Humidity Chaux-de-Fonds" -group Environment -format "%s%%" -update 10m \
        -get {thc_MeteoSwiss {"CDF" "humidity"}}
 thc::DefineJob -tag Surv -description "Alarm detection" \
                -condition {$Event(Alarm,state)==1} {

    thc::Set {Sirene,state LightLiving,state} 1
    thc::Log "Alarm on" 1

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

    thc::DefineJob -tag LightOff -description "Switch off the alarm lights" -time +45m {
       thc::Set LightLiving,state 0
       thc::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 ThcDebug.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>