99_PRIV.pm 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ##############################################
  2. # Example perl functions. Put this file into the FHEM directory.
  3. #
  4. # # Activate 2 rollades at once with one button, open them to
  5. # # a different degree.
  6. # define ntfy_1 notifyon btn3 {MyFunc("@", "%")}
  7. #
  8. # # Swith the heater off if all FHT actuators are closed,
  9. # # and on if at least one is open
  10. # define at_1 at +*00:05 { fhem "set heater " . (sumactuator()?"on":"off") };
  11. package main;
  12. use strict;
  13. use warnings;
  14. sub
  15. PRIV_Initialize($$)
  16. {
  17. my ($hash, $init) = @_;
  18. }
  19. sub
  20. sumactuator()
  21. {
  22. my $sum = 0;
  23. foreach my $d (keys %defs) {
  24. next if($defs{$d}{TYPE} ne "FHT");
  25. my ($act, undef) = split(" ", $defs{$d}{READINGS}{"actuator"}{VAL});
  26. $act =~ s/%//;
  27. $sum += $act;
  28. }
  29. return $sum;
  30. }
  31. sub
  32. MyFunc($$)
  33. {
  34. my ($a1, $a2) = @_;
  35. Log 2, "Device $a1 was set to $a2 (type: $defs{$a1}{TYPE})";
  36. if($a2 eq "on") {
  37. fhem "set roll1 on-for-timer 10";
  38. fhem "set roll2 on-for-timer 16";
  39. } else {
  40. fhem "set roll1 off";
  41. fhem "set roll2 off";
  42. }
  43. }
  44. 1;