#
# fhem.pl configfile
# 
# Define an FHT80b device. You have to know its transmitter code,
# or set verbose to 4 and wait for a while watching the log.
#
# wz stands for "wohnzimmer".
# After about 5-10 minutes, check if "list wz" returns something meaningful
#

attr global logfile /tmp/fhem-%Y-%m.log
attr global statefile /tmp/fhem.save    # where to save the state of the devices
attr global verbose 3                   # "normal" verbosity
attr global port 7072                   # our TCP/IP port (localhost only)
attr global modpath .                   # where our FHEM directory is

define FHZ FHZ /dev/tts/USB0 # the serial port of an FHZ 1000 PC

# Since it is said that FHZ1x00 sometimes forgets its own random-initialized
# FHTcode (Contronics speak: "Zentralencode"; sometimes called "fhtid"),
# it's probably a good idea to manually hard-code it.
# Changing the value (range is 1 to 99) needs re-registration of FHT80b
# via their "cent" menu item (instructions see FAQ).
# set FHZ FHTcode XX


define wz FHT 3232          # type FHT, transmitter code 3232 (default value)

#########################
# Some documentation suggests that the FHZ time should be set every minute.
# I only set it once a day.
define fhz_timer at *03:30:00 set FHZ time

#########################
# If you wish to have up-to date information on certain parameters which can be
# modified on the FHT80b itself, then enable the line below. My device sends a
# message when a value changes, and sends measured-temp, actuator and state
# messages regularly, so I do not use this command.
# Be patient: the reply comes after 5-10 minutes.
#define wz_refresh at *04:00:00 set wz report1 255 report2 255

# alias for the above
#define wz_refresh at *04:00:00 set wz refreshvalues


###################
# If at the weekly lime-protection time (usually saturday at 11:00 AM) the
# desired temperature is lower than the measured temperature, then you'll get
# instead of "actuator:0%" the "actuator:lime-protection" messsages every 2.5
# minutes.  I think this is an FHT80b firmware bug, a workaround is to set the
# desired temperature for a short time higher than the measured temperature.
# You can automate it (for all FHT's) with the following notify:

define lime_reset notify .*lime-protection {\
  my $d = $defs{@}{READINGS}{"desired-temp"}{VAL};;\
  my $m = $defs{@}{READINGS}{"measured-temp"}{VAL};;\
  if($m > $d) {\
    fhem("set @ desired-temp 29");;\
    fhem("set @ desired-temp $d");;\
  }\
}
