Advertisement
jagheadg

alarm_clock.rules

Jul 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. var Timer timerPERSON1Alarm = null
  2.  
  3. rule "Person1 preset load"
  4. when
  5. Item PERSON1_ALARM_PRESETS received command
  6. then
  7. var int toMinute
  8. var int toHour
  9. var int RunTime
  10. switch (PERSON1_ALARM_PRESETS.state) {
  11. //early shift
  12. case 1: {
  13. toHour=4
  14. toMinute=0
  15. RunTime=40
  16. }
  17. //late shift
  18. case 2: {
  19. toHour=10
  20. toMinute=0
  21. RunTime=40
  22. }
  23. }
  24. //set hour,minute,runtime items for each day
  25. var i = 0
  26. var Day= "NA"
  27. //don't change saturday/sunday. set i max=7 and uncomment cases if you have to work weekends, you unlucky soul
  28. while ((i=i+1) <= 5) {
  29. switch i {
  30. case 1: Day = "MON"
  31. case 2: Day = "TUE"
  32. case 3: Day= "WED"
  33. case 4: Day= "THU"
  34. case 5: Day= "FRI"
  35. //case 6: Day= "SAT"
  36. //case 7: Day= "SUN"
  37. }
  38. //set all hours
  39. gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_H").forEach[s | s.postUpdate(toHour)]
  40. //set all minutes
  41. gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_M").forEach[s | s.postUpdate(toMinute)]
  42. //set runtimes
  43. gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_RUN").forEach[s | s.postUpdate(RunTime)]
  44. }
  45. end
  46.  
  47.  
  48. rule "Alarm PERSON1"
  49. when
  50. Time cron "0 0/1 * * * ?"
  51. then
  52. var Today = ""
  53. var boolean Wakeup = false
  54. var int toMinute
  55. var int toHour
  56. var int RunTime
  57.  
  58. switch now.getDayOfWeek{
  59. case 1: Today = "MON"
  60. case 2: Today = "TUE"
  61. case 3: Today = "WED"
  62. case 4: Today = "THU"
  63. case 5: Today = "FRI"
  64. case 6: Today = "SAT"
  65. case 7: Today = "SUN"
  66. }
  67.  
  68. if (gPERSON1AlarmSet.members.filter[s | s.name == "PERSON1_ALARM_"+Today].head.state == ON) {
  69. toMinute = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_M"].head.state as Number).intValue
  70. toHour = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_H"].head.state as Number).intValue
  71. RunTime = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_RUN"].head.state as Number).intValue
  72. Wakeup = true
  73. }
  74.  
  75. if (toMinute == now.getMinuteOfHour && toHour == now.getHourOfDay && Wakeup==true) {
  76. //ALARM_ACTIVE to ON, so you can react to a move sensor downstairs or in the kitchen
  77. // i use this for a squeezeboxspeak "Good morning. it is soandsomuch degrees"
  78. // see rule "react to move"
  79. //remove all references if you don't want/need this
  80. sendCommand(PERSON1_ALARM_ACTIVE,ON)
  81. //Do Stuff here, like turn on lights,coffee machine and/or radio
  82.  
  83. timerPERSON1Alarm = createTimer(now.plusMinutes(RunTime)) [|
  84. //turn lights,radio etc. of after defined time for day.
  85. //sanity check turn off wecker_aktiv
  86. sendCommand(PERSON1_ALARM_ACTIVE,OFF)
  87. timerPERSON1Alarm = null
  88. ]
  89. }
  90. end
  91.  
  92. rule "react to move"
  93. when
  94. Item your_move_sensor received update 1
  95. then
  96.  
  97. //PERSON1 reached first floor/kitchen
  98. if (PERSON1_ALARM_ACTIVE.state==ON){
  99.  
  100. // example for squeezebox squeezeboxSpeak("Your_box", "Guten Morgen PERSON1. Es sind "+String::format("%.2f", (Terasse_temp.state as DecimalType).floatValue())+" Grad.", 80, true)
  101. //wecker_aktiv to off, else speech would be repeated each time sensor is triggered
  102. sendCommand(PERSON1_ALARM_ACTIVE,OFF)
  103. }
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement