99_ALARM.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #############################################
  2. # Low Budget ALARM System
  3. ##############################################
  4. # ATTENTION! This is more a toy than a professional alarm system!
  5. # You must know what you do!
  6. ##############################################
  7. #
  8. # Concept:
  9. # 1x Signal Light (FS20 allight) to show the status (activated/deactivated)
  10. # 2x Sirene (in/out) (FS20 alsir1 alsir2 )
  11. # 2x PIRI-2 (FS20 piriu pirio)
  12. # 1x Sender (FS20 alsw) to activate/deactivate the system.
  13. # Tip: use the KeyMatic CAC with pin code or
  14. # optional a normal sender (FS20 alsw2)
  15. #
  16. # Add something like the following lines to the configuration file :
  17. # notifyon alsw {MyAlsw()}
  18. # notifyon alsw2 {MyAlswNoPin()}
  19. # notifyon piriu {MyAlarm()}
  20. # notifyon pirio {MyAlarm()}
  21. # and put this file in the <modpath>/FHZ1000 directory.
  22. #
  23. # Martin Haas
  24. ##############################################
  25. package main;
  26. use strict;
  27. use warnings;
  28. sub
  29. ALARM_Initialize($$)
  30. {
  31. my ($hash) = @_;
  32. }
  33. ##############################################
  34. # Switching Alarm System on or off
  35. sub
  36. MyAlsw()
  37. {
  38. my $ON="set allight on; setstate alsw on";
  39. my $OFF="set allight off; set alsir1 off; set alsir2 off; setstate alsw off";
  40. if ( -e "/var/tmp/alertsystem")
  41. {
  42. unlink "/var/tmp/alertsystem";
  43. #Paranoia
  44. for (my $i = 0; $i < 2; $i++ )
  45. {
  46. fhem "$OFF";
  47. };
  48. Log 2, "alarm system is OFF";
  49. } else {
  50. system "touch /var/tmp/alertsystem";
  51. #Paranoia
  52. for (my $i = 0; $i < 2; $i++ )
  53. {
  54. fhem "$ON"
  55. }
  56. Log 2, "alarm system is ON";
  57. };
  58. }
  59. ##############################################
  60. # If you have no Keymatic then use this workaround:
  61. # After 4x pushing a fs20-button within some seconds it will activate/deactivate the alarm system.
  62. sub
  63. MyAlswNoPin()
  64. {
  65. my $timedout=5;
  66. ## first time
  67. if ( ! -e "/var/tmp/alontest1")
  68. {
  69. for (my $i = 1; $i < 4; $i++ )
  70. {
  71. system "touch -t 200601010101 /var/tmp/alontest$i";
  72. }
  73. }
  74. ## test 4 times
  75. my $now= `date +%s`;
  76. for (my $i = 1; $i < 4; $i++ )
  77. {
  78. my $tagx=`date -r /var/tmp/alontest$i +%s`;
  79. my $testx=$now-$tagx;
  80. if ( $testx > $timedout )
  81. {
  82. system "touch /var/tmp/alontest$i";
  83. die "test$i: more than $timedout sec";
  84. }
  85. }
  86. system "touch -t 200601010101 /var/tmp/alontest*";
  87. Log 2, "ok, let's switch the alarm system...";
  88. #if you only allow to activate (and not deactivate) with this script:
  89. # if ( -e "/var/tmp/alertsystem") { die "deactivating alarm system not allowed"};
  90. MyAlsw();
  91. }
  92. ##############################################
  93. # ALARM! Do what you want!
  94. sub
  95. MyAlarm()
  96. {
  97. #alarm-system activated??
  98. if ( -e "/var/tmp/alertsystem")
  99. {
  100. my $timer=180; # time until the sirene will be quiet
  101. my $ON1="set alsir1 on-for-timer $timer";
  102. my $ON2="set alsir2 on-for-timer $timer";
  103. #Paranoia
  104. for (my $i = 0; $i < 2; $i++ )
  105. {
  106. fhem "$ON1";
  107. fhem "$ON2";
  108. }
  109. Log 2, "ALARM! #################" ;
  110. # have fun
  111. my @lights=("stuwz1", "stuwz2", "nachto", "nachtu", "stoliba" ,"stlileo");
  112. my @rollos=("rolu4", "rolu5", "roloadi", "rololeo", "roloco", "rolowz", "rolunik1", "rolunik2");
  113. foreach my $light (@lights) {
  114. fhem "set $light on"
  115. }
  116. foreach my $rollo (@rollos) {
  117. fhem "set $rollo on"
  118. }
  119. }
  120. }
  121. 1;