FHEM Forum

FHEM => English Corner => Thema gestartet von: Fonz am 05 Februar 2013, 11:24:54

Titel: Where do I put sub routines?
Beitrag von: Fonz am 05 Februar 2013, 11:24:54
Hi,

Thanks again for this great application.

Im learning a lot but would like to include a sub routine into Fhem.

I have seen some code that I would like to include, but I dont know where to put it?

Can I just put the following in the config file, or do I need to put it into one of the 99 files?

By the way, what are the 99 files for?

Here is the code, if someone could tell me where to paste it I would be very grateful.

Zitat16. Setting auto-mode from manual for the FHT won't change the desired temperature!

Thanks to Waldemar Porsche the following notify will take care of that:
define ExtendedAutoMode notify .*mode.*auto {\
    $r = $defs{@}{READINGS};;\
    return if (!defined($r));;\
    my $olddesired = $r->{"desired-temp"}{VAL};;\
    return if (!defined($olddesired));;\
    my @@day = ("sun", "mon", "tue", "wed", "thu", "fri", "sat");;\
    my $now = sprintf("%%02d:%%02d", $hour, $min);;\
    my $wd = $day[$wday];;\
    my $desired;;\
    if (defined($r->{"warnings"}{VAL}) && $r->{"warnings"}{VAL} eq "Window open") {\
      $desired = $r->{"windowopen-temp"}{VAL};;\
    } elsif (defined($r->{"$wd-from1"}{VAL}) && $r->{"$wd-from1"}{VAL} le $now && defined($r->{"$wd-to1"}{VAL}) && $r->{"$wd-to1"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};;\
    } elsif (defined($r->{"$wd-from2"}{VAL}) && $r->{"$wd-from2"}{VAL} le $now && defined($r->{"$wd-to2"}{VAL}) && $r->{"$wd-to2"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};;\
    } else {\
      $desired = $r->{"night-temp"}{VAL};;\
    }\
    fhem ("set @ desired-temp $desired") if (defined($desired) && $desired ne $olddesired);;\
  }
  attr ExtendedAutoMode comment Setzt fuer den Auto mode die desired-temp in Abhaengigkeit von Temperaturprofil und Fensterkontakt

Fon
Titel: Aw: Where do I put sub routines?
Beitrag von: jhohn am 05 Februar 2013, 11:40:04
create a file 99_myUtils.pm in fhem/FHEM and put it in there. Then restart fhem. Files beginning with 99_ will be automatically included on system start.
Titel: Aw: Where do I put sub routines?
Beitrag von: jhohn am 05 Februar 2013, 11:41:20
missing that edit mode ...


the notify needs to be in fhem.cfg
Titel: Aw: Where do I put sub routines?
Beitrag von: Fonz am 05 Februar 2013, 13:38:06
Thanks for the reply.

So the line

Zitatdefine ExtendedAutoMode notify .*mode.*auto {\

should be in the cfg file and then,

Zitat$r = $defs{@}{READINGS};;\
    return if (!defined($r));;\
    my $olddesired = $r->{"desired-temp"}{VAL};;\
    return if (!defined($olddesired));;\
    my @@day = ("sun", "mon", "tue", "wed", "thu", "fri", "sat");;\
    my $now = sprintf("%%02d:%%02d", $hour, $min);;\
    my $wd = $day[$wday];;\
    my $desired;;\
    if (defined($r->{"warnings"}{VAL}) && $r->{"warnings"}{VAL} eq "Window open") {\
      $desired = $r->{"windowopen-temp"}{VAL};;\
    } elsif (defined($r->{"$wd-from1"}{VAL}) && $r->{"$wd-from1"}{VAL} le $now && defined($r->{"$wd-to1"}{VAL}) && $r->{"$wd-to1"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};;\
    } elsif (defined($r->{"$wd-from2"}{VAL}) && $r->{"$wd-from2"}{VAL} le $now && defined($r->{"$wd-to2"}{VAL}) && $r->{"$wd-to2"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};;\
    } else {\
      $desired = $r->{"night-temp"}{VAL};;\
    }\
    fhem ("set @ desired-temp $desired") if (defined($desired) && $desired ne $olddesired);;\
  }
  attr ExtendedAutoMode comment Setzt fuer den Auto mode die desired-temp in Abhaengigkeit von Temperaturprofil und Fensterkontakt

Should be in the newly created 99_myUtils.pm file?

It or should only the

Zitatdefine ExtendedAutoMode notify .*mode.*auto

Be in the CFG file? with the rest in the 99_myUtils.pm file?

Thanks again,

Fonz

Titel: Aw: Where do I put sub routines?
Beitrag von: jhohn am 05 Februar 2013, 15:07:30
This whole thing lookes just like one notify and needs to be in fhem.cfg. The last line, beginning with attr, is a comment telling "this will set the desired-temp for auto-mode respecting temp-profiles and window contacts"

Titel: Aw: Where do I put sub routines?
Beitrag von: Fonz am 05 Februar 2013, 15:27:21
Thank you Jhohn.

Fonz
Titel: Aw: Where do I put sub routines?
Beitrag von: Fonz am 05 Februar 2013, 15:48:31
Ok, I have put the whole thing into the CFG file,

This should theoreticly adjust the deisered temperature of the unit if I set the mode to auto.

However, I seem to have the following error in the log,

Zitat2013.02.05 14:40:38 5: Cmd: >set Rear mode auto<
2013.02.05 14:40:38 5: CUL sending T28343e00
2013.02.05 14:40:38 5: SW: T28343e00
2013.02.05 14:40:38 2: FHT set Rear mode auto
2013.02.05 14:40:38 5: Triggering Rear (1 changes)
2013.02.05 14:40:38 5: Rear trigger: Checking ExtendedAutoMode for notify
2013.02.05 14:40:38 5: Triggering ExtendedAutoMode
2013.02.05 14:40:38 5: Cmd: >{\
    $r = $defs{Rear}{READINGS};\
    return if (!defined($r));\
    my $olddesired = $r->{"desired-temp"}{VAL};\
    return if (!defined($olddesired));\
    my @day = ("sun", "mon", "tue", "wed", "thu", "fri", "sat");\
    my $now = sprintf("%02d:%02d", $hour, $min);\
    my $wd = $day[$wday];\
    my $desired;\
    if (defined($r->{"warnings"}{VAL}) && $r->{"warnings"}{VAL} eq "Window open") {\
      $desired = $r->{"windowopen-temp"}{VAL};\
    } elsif (defined($r->{"$wd-from1"}{VAL}) && $r->{"$wd-from1"}{VAL} le $now && defined($r->{"$wd-to1"}{VAL}) && $r->{"$wd-to1"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};\
    } elsif (defined($r->{"$wd-from2"}{VAL}) && $r->{"$wd-from2"}{VAL} le $now && defined($r->{"$wd-to2"}{VAL}) && $r->{"$wd-to2"}{VAL} ge $now) {\
      $desired = $r->{"day-temp"}{VAL};\
    } else {\
      $desired = $r->{"night-temp"}{VAL};\
    }\
    fhem ("set Rear desired-temp $desired") if (defined($desired) && $desired ne $olddesired);\
  }<
2013.02.05 14:40:38 3: ExtendedAutoMode return value: Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.
Global symbol "$r" requires explicit package name at (eval 18) line 1.

This script was taken from this link, http://fhem.de/faq.html (//fhem.de/faq.html) item number 16.

Is it possible that something has happend with the formatting? As I have copied it exactly..?

Many thanks again,

Fonz
Titel: Aw: Where do I put sub routines?
Beitrag von: jhohn am 05 Februar 2013, 16:04:04
try
my $r = ...
Titel: Aw: Where do I put sub routines?
Beitrag von: Fonz am 05 Februar 2013, 16:23:32
That Worked, thank you very much Jhohn.

Is there anyway for me to notify anyone of this error so its corrected in the FAQ, to stop other noobs like myself making this mistake?