-
Notifications
You must be signed in to change notification settings - Fork 130
Hints and tips
In many cases you will want to add more parameters to MisterHouse objects, e.g.
$Dining_room_radiator->{room_name} = "Dining room";
Unfortunately these parameters become undefined each time that MisterHouse starts, so need to be initialised each time. There is a number of ways to do this.
If they are static, then you can do it in your items.mht
file e.g.
GENERIC, Back_hall_detector, variable
CODE, $Back_hall_detector->{room_name} = "Dining room";
Or in an initialising perl script e.g.
if ( $Startup or $Reload ) {
$Back_hall_detector->{room_name} = "Dining room";
}
If they are volatile, then each time they change you will have to save this away in a file, then on startup add the routine that reloads the values from this file to your initialisation script above.
If you have a lot of dynamically overloaded items, you can save a huge amount of code by implementing dynamic overloading.
The first line of a vsDB data file contains the names of the columns e.g.
ID name room on_off timeHHMI
1 Main_bedroom_radiator Main bedroom on 08:00
It is then possible to create a generic, extensible overloading routine that for each row of the file overloads the MisterHouse Item that matches the `name' then sets the values for each column e.g. in this case it would set
$Main_bedroom_radiator->{room} = "Main bedroom";
$Main_bedroom_radiator->{on_off} = "on";
$Main_bedroom_radiator->{timeHHMI} = "08:00";
By using the column names this way you can add extra overloads by just adding them to the datafile e.g changing the datafile to;
ID Name Room on_off timeHHMI days
1 Main bed on morning Main bedroom on 08:00 SMTWTFS
Would also set
$Main_bedroom_radiator->{days} = "SMTWTFS";
Without any change to your overloading code.
It looks like this in Pseudocode;
Read in the first line of the datafile
Split it to get a list of column names
For each subsequent row
split it to get the values
$this_object = get_object_by_name(<name value>)
for each of the subsequent columns
$this_object->{<column_name>} = <column value>
next column
next row
Ìn order to be able to turn logging on and off without restarting MisterHouse, define a generic item GENERIC, logging_level, Variable
in items.mht
and create a new logger e.g.
#-----------------------------------------------------------------------
# write_log (text)
# writes a log message when logging_level > 0
#-----------------------------------------------------------------------
sub write_log {
my $message = $_[0];
if ( $logging_level->{state} > 0 ) {
print_log($message);
}
return;
}
Then use write_log(zzz)
instead of print_log(zzz)
and it will only fill your log when logging_level > 0