Autor Thema: Where do I put sub routines?  (Gelesen 9493 mal)

Fonz

  • Gast
Where do I put sub routines?
« 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.

Zitat
16. 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

Offline jhohn

  • Full Member
  • ***
  • Beiträge: 244
    • http://www.pcs4kids.org
Aw: Where do I put sub routines?
« Antwort #1 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.
FHEM auf Synology Diskstation DS413j (DSM4.3), HM LAN Adapter
Steuerung für Nachtspeicheröfen:
Ladung:   HM-WDS10-TH-O, HM-LC-Sw4-DR, Weather-Modul
Gebläse: HM-CC-TC, HM-LC-SW1-FM, HM-Sec-RHS
FHEM auf FritzBox 7390 für Telefon Funktionen

Offline jhohn

  • Full Member
  • ***
  • Beiträge: 244
    • http://www.pcs4kids.org
Aw: Where do I put sub routines?
« Antwort #2 am: 05 Februar 2013, 11:41:20 »
missing that edit mode ...


the notify needs to be in fhem.cfg
FHEM auf Synology Diskstation DS413j (DSM4.3), HM LAN Adapter
Steuerung für Nachtspeicheröfen:
Ladung:   HM-WDS10-TH-O, HM-LC-Sw4-DR, Weather-Modul
Gebläse: HM-CC-TC, HM-LC-SW1-FM, HM-Sec-RHS
FHEM auf FritzBox 7390 für Telefon Funktionen

Fonz

  • Gast
Aw: Where do I put sub routines?
« Antwort #3 am: 05 Februar 2013, 13:38:06 »
Thanks for the reply.

So the line

Zitat
define 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

Zitat
define ExtendedAutoMode notify .*mode.*auto


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

Thanks again,

Fonz


Offline jhohn

  • Full Member
  • ***
  • Beiträge: 244
    • http://www.pcs4kids.org
Aw: Where do I put sub routines?
« Antwort #4 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"

FHEM auf Synology Diskstation DS413j (DSM4.3), HM LAN Adapter
Steuerung für Nachtspeicheröfen:
Ladung:   HM-WDS10-TH-O, HM-LC-Sw4-DR, Weather-Modul
Gebläse: HM-CC-TC, HM-LC-SW1-FM, HM-Sec-RHS
FHEM auf FritzBox 7390 für Telefon Funktionen

Fonz

  • Gast
Aw: Where do I put sub routines?
« Antwort #5 am: 05 Februar 2013, 15:27:21 »
Thank you Jhohn.

Fonz

Fonz

  • Gast
Aw: Where do I put sub routines?
« Antwort #6 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,

Zitat
2013.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 item number 16.

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

Many thanks again,

Fonz

Offline jhohn

  • Full Member
  • ***
  • Beiträge: 244
    • http://www.pcs4kids.org
Aw: Where do I put sub routines?
« Antwort #7 am: 05 Februar 2013, 16:04:04 »
try
my $r = ...
FHEM auf Synology Diskstation DS413j (DSM4.3), HM LAN Adapter
Steuerung für Nachtspeicheröfen:
Ladung:   HM-WDS10-TH-O, HM-LC-Sw4-DR, Weather-Modul
Gebläse: HM-CC-TC, HM-LC-SW1-FM, HM-Sec-RHS
FHEM auf FritzBox 7390 für Telefon Funktionen

Fonz

  • Gast
Aw: Where do I put sub routines?
« Antwort #8 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?


 

decade-submarginal