Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Timer timerPERSON1Alarm = null
- rule "Person1 preset load"
- when
- Item PERSON1_ALARM_PRESETS received command
- then
- var int toMinute
- var int toHour
- var int RunTime
- switch (PERSON1_ALARM_PRESETS.state) {
- //early shift
- case 1: {
- toHour=4
- toMinute=0
- RunTime=40
- }
- //late shift
- case 2: {
- toHour=10
- toMinute=0
- RunTime=40
- }
- }
- //set hour,minute,runtime items for each day
- var i = 0
- var Day= "NA"
- //don't change saturday/sunday. set i max=7 and uncomment cases if you have to work weekends, you unlucky soul
- while ((i=i+1) <= 5) {
- switch i {
- case 1: Day = "MON"
- case 2: Day = "TUE"
- case 3: Day= "WED"
- case 4: Day= "THU"
- case 5: Day= "FRI"
- //case 6: Day= "SAT"
- //case 7: Day= "SUN"
- }
- //set all hours
- gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_H").forEach[s | s.postUpdate(toHour)]
- //set all minutes
- gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_M").forEach[s | s.postUpdate(toMinute)]
- //set runtimes
- gPERSON1Alarm.members.filter(s|s.name == "PERSON1_ALARM_"+Day+"_RUN").forEach[s | s.postUpdate(RunTime)]
- }
- end
- rule "Alarm PERSON1"
- when
- Time cron "0 0/1 * * * ?"
- then
- var Today = ""
- var boolean Wakeup = false
- var int toMinute
- var int toHour
- var int RunTime
- switch now.getDayOfWeek{
- case 1: Today = "MON"
- case 2: Today = "TUE"
- case 3: Today = "WED"
- case 4: Today = "THU"
- case 5: Today = "FRI"
- case 6: Today = "SAT"
- case 7: Today = "SUN"
- }
- if (gPERSON1AlarmSet.members.filter[s | s.name == "PERSON1_ALARM_"+Today].head.state == ON) {
- toMinute = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_M"].head.state as Number).intValue
- toHour = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_H"].head.state as Number).intValue
- RunTime = (gPERSON1Alarm.members.filter[s | s.name == "PERSON1_ALARM_"+Today+"_RUN"].head.state as Number).intValue
- Wakeup = true
- }
- if (toMinute == now.getMinuteOfHour && toHour == now.getHourOfDay && Wakeup==true) {
- //ALARM_ACTIVE to ON, so you can react to a move sensor downstairs or in the kitchen
- // i use this for a squeezeboxspeak "Good morning. it is soandsomuch degrees"
- // see rule "react to move"
- //remove all references if you don't want/need this
- sendCommand(PERSON1_ALARM_ACTIVE,ON)
- //Do Stuff here, like turn on lights,coffee machine and/or radio
- timerPERSON1Alarm = createTimer(now.plusMinutes(RunTime)) [|
- //turn lights,radio etc. of after defined time for day.
- //sanity check turn off wecker_aktiv
- sendCommand(PERSON1_ALARM_ACTIVE,OFF)
- timerPERSON1Alarm = null
- ]
- }
- end
- rule "react to move"
- when
- Item your_move_sensor received update 1
- then
- //PERSON1 reached first floor/kitchen
- if (PERSON1_ALARM_ACTIVE.state==ON){
- // example for squeezebox squeezeboxSpeak("Your_box", "Guten Morgen PERSON1. Es sind "+String::format("%.2f", (Terasse_temp.state as DecimalType).floatValue())+" Grad.", 80, true)
- //wecker_aktiv to off, else speech would be repeated each time sensor is triggered
- sendCommand(PERSON1_ALARM_ACTIVE,OFF)
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement