Skip to content
ggodart edited this page Jan 30, 2021 · 6 revisions

Hints and tips

Overloading

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.

Logging

Ì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

Clone this wiki locally