trueDisplay State: OfftruefalsetrueShortcut: Sleep infofalseSleep infotrueUser PresenttruetrueExpression: global_get_dat==global_old_date OR global_get_dat>global_old_dateglobal_get_dat==global_old_date OR global_get_dat>global_old_datetrueExpression: isEmpty(global_old_date);isEmpty(global_old_date);trueExpression: setting_alarm_volume=="15";setting_alarm_volume=="15";trueFlow Executing: Auto_alarm(required)Auto_alarm(required)trueTime Range: between 10:00 PM - 12:00 AMMonTueWedThuFriSatSun22000trueTime Range: between 10:00 PM - 4:00 AMMonTueWedThuFriSatSun22040trueInit Variable System Setting: System volume_alarm_speaker to setting_alarm_volumeSYSTEMvolume_alarm_speakersetting_alarm_volumetrueMessage Dialog: Your last night sleep was about {global_abc,numberformat,00} hour and {global_xyz,numberformat,00} minutes [Note: based on first alarm, which was on {global_first_alarm}, and sleep start time {global_sleep_on_hr}:{global_sleep_on_min}}Your last night sleep was about{global_abc,numberformat,00} hour and {global_xyz,numberformat,00} minutes
[Note: based on first alarm, which was on {global_first_alarm},
and sleep start time {global_sleep_on_hr}:{global_sleep_on_min}}Okfalse5000trueScript: //this caluculates how much sleep you got, by using first alarm time as wake up time. sleep_off_hr=first_alarm_hr; sleep_off_min=first_alarm_min; if(global_sleep_on_hr>12 AND sleep_off_hr<12) { if((sleep_off_min-global_sleep_on_min)>=0){ net_sleep_hr=sleep_off_hr+(24-global_sleep_on_hr); net_sleep_min=(sleep_off_min-global_sleep_on_min);} else {net_sleep_min=60-abs(sleep_off_min-global_sleep_on_min); net_sleep_hr=sleep_off_hr+(24-global_sleep_on_hr)-1;} } else { if((sleep_off_min-global_sleep_on_min)>=0){ net_sleep_hr=sleep_off_hr-global_sleep_on_hr; net_sleep_min=(sleep_off_min-global_sleep_on_min);} else {net_sleep_min=60-abs(sleep_off_min-global_sleep_on_min); net_sleep_hr=sleep_off_hr-global_sleep_on_hr-1; } } global_abc=net_sleep_hr; global_xyz=net_sleep_min; global_first_alarm="{first_alarm_hr,numberformat,00}"+":"+"{first_alarm_min,numberformat,00}";trueScript: //this notes down time when device is locked last time or we can say time when you go to sleep global_sleep_on_hr="{triggertime,dateformat,HH}"; global_sleep_on_min="{triggertime,dateformat,mm}";trueScript: //this notes first alarm time first_alarm_hr=global_hour; first_alarm_min=global_min;trueScript: global_current = "{getDate(),dateformat,HH}"; global_current_min = "{getDate(),dateformat,mm}"; global_total= global_current+04;//hour global_total_min= global_current_min+45;//min //your sleep= 4hr+ 45minutes+ 2hr(already spent in action:sleep )=6hr 45min //suppose you want 6 hr 30min sleep,remove 2hr from 6hr30min so, that's 4hr30min, now set, global_total=global_current+4 and global_total_min= global_current_min+30. All Done! //NOTE: suppose you've changed default 120 min to 90 min than remove 90 min instead of 120 min if (global_total<24) {global_hour="{global_total,numberformat,00}"; } else {global_hour=global_total-24; global_hour="{global_hour,numberformat,00}"; } if (global_total_min<60) {global_min="{global_total_min,numberformat,00}";; } else {x=(floor(global_total_min/60)); global_hour=global_hour + (x); global_min=global_total_min-(60*x); global_hour="{global_hour,numberformat,00}"; global_min="{global_min,numberformat,00}"; }trueScript: global_get_dat="{getDate(),dateformat,dd}"; if(abs(global_get_dat-global_old_date)>20) { global_get_dat=0;}trueScript: global_old_date="{addDays(getDate(),1),dateformat,dd}";falseScript: if((global_min+10)<60) {global_min=global_min+10; } else {y=((global_min+10)/60); x=(floor(y)); global_hour=global_hour + floor(x); global_min=(global_min+10)-(60*x); } alarm222falseScript: if((global_min+10)<60) {global_min=global_min+10; } else {y=((global_min+10)/60); x=(floor(y)); global_hour=global_hour + floor(x); global_min=(global_min+10)-(60*x); } alarm2222trueSet Alarm: at {global_hour}:{global_min} (Default){global_hour}{global_min}falsetruetrueSet Audio Stream Volume: Alarm to level 14ALARMADJUST_SET_ABSOLUTE14falsetruetrueSleep: 2h (allow device sleep)2hfalsetruetrueSleep: 2s (allow device sleep)2sfalsetruefalseStop Flows: Auto_alarm(required)Auto_alarm(required)trueTurn Screen On: Dim for 5sfalse5strueauto alarm terminate(required)Auto Alarm falsePARALLELUser PresentThis flow stops Auto alarm if device gets UnlockedFlow Executing: Auto_alarm(required)Stop Flows: Auto_alarm(required)Auto_alarm(required)Auto Alarm falseSKIP500This expression will only becames true when date changesIt is assumed, that you go to sleep during this period.(10 to 4)
If you change this than also change the expression 2 steps below(currently 10 to 12)
suppose you change this to 9:00 to 4:00 than also change following expression that is below that to 9:00 to 12:00between 10 to 12 date is yet to be changed. so, the flow will not run. so, that is why i have placed a condition to allow flow to continue between this periodTurn Screen On: Dim for 5sSet Alarm: at {global_hour}:{global_min} (Default)Script: //this notes down time when device is locked last time or we can say time when you go to sleep global_sleep_on_hr="{triggertime,dateformat,HH}"; global_sleep_on_min="{triggertime,dateformat,mm}";Script: global_old_date="{addDays(getDate(),1),dateformat,dd}";Please read the notes on the right side of the flow carefully. That is very important.
notes on left are explanationIt is assumed, that you go to sleep during this period.Display State: OffExpression: isEmpty(global_old_date);Time Range: between 10:00 PM - 4:00 AMScript: global_old_date="{addDays(getDate(),1),dateformat,dd}";Time Range: between 10:00 PM - 12:00 AMSet Audio Stream Volume: Alarm to level 14Expression: setting_alarm_volume=="15";Alarm will be set ,if device remain locked for 120 minutes.
if you want to change that, than you will also have to modify that into script below it. more details provided there.Sleep: 2h (allow device sleep)This flow will not run during the day so don't worry. make sure you also downloaded other flow. both are required.
3rd flow named last_sleep is optional if you want to track sleep.Init Variable System Setting: System volume_alarm_speaker to setting_alarm_volumeScript: //this notes first alarm time first_alarm_hr=global_hour; first_alarm_min=global_min;Set Alarm: at {global_hour}:{global_min} (Default)Script: //this caluculates how much sleep you got, by using first alarm time as wake up time. sleep_off_hr=first_alarm_hr; sleep_off_min=first_alarm_min; if(global_sleep_on_hr>12 AND sleep_off_hr<12) { if((sleep_off_min-global_sleep_on_min)>=0){ net_sleep_hr=sleep_off_hr+(24-global_sleep_on_hr); net_sleep_min=(sleep_off_min-global_sleep_on_min);} else {net_sleep_min=60-abs(sleep_off_min-global_sleep_on_min); net_sleep_hr=sleep_off_hr+(24-global_sleep_on_hr)-1;} } else { if((sleep_off_min-global_sleep_on_min)>=0){ net_sleep_hr=sleep_off_hr-global_sleep_on_hr; net_sleep_min=(sleep_off_min-global_sleep_on_min);} else {net_sleep_min=60-abs(sleep_off_min-global_sleep_on_min); net_sleep_hr=sleep_off_hr-global_sleep_on_hr-1; } } global_abc=net_sleep_hr; global_xyz=net_sleep_min; global_first_alarm="{first_alarm_hr,numberformat,00}"+":"+"{first_alarm_min,numberformat,00}";Set Alarm: at {global_hour}:{global_min} (Default)Set Alarm: at {global_hour}:{global_min} (Default)Script: if((global_min+10)<60) {global_min=global_min+10; } else {y=((global_min+10)/60); x=(floor(y)); global_hour=global_hour + floor(x); global_min=(global_min+10)-(60*x); } alarm2222Sleep: 2s (allow device sleep)This sets global_old_date to one day ahead , so the condition:expression at the start will stay false unless the date changesScript: if((global_min+10)<60) {global_min=global_min+10; } else {y=((global_min+10)/60); x=(floor(y)); global_hour=global_hour + floor(x); global_min=(global_min+10)-(60*x); } alarm2222Sleep: 2s (allow device sleep)Remove this 3 , if you don't want maximum alarm volume to be set everytimeExpression: global_get_dat==global_old_date OR global_get_dat>global_old_dateScript: global_get_dat="{getDate(),dateformat,dd}"; if(abs(global_get_dat-global_old_date)>20) { global_get_dat=0;}Script: if((global_min+10)<60) {global_min=global_min+10; } else {y=((global_min+10)/60); x=(floor(y)); global_hour=global_hour + floor(x); global_min=(global_min+10)-(60*x); } alarm222Sleep: 2s (allow device sleep)4 alarms will be set at interval of 10 min, if you want to change interval ,edit this script, set value of Alarm_interval as you would likeSpecify how much sleep you need.(Read comments of this script)
Default sleep is 6 hr 45 minScript: global_current = "{getDate(),dateformat,HH}"; global_current_min = "{getDate(),dateformat,mm}"; global_total= global_current+04;//hour global_total_min= global_current_min+45;//min //your sleep= 4hr+ 45minutes+ 2hr(already spent in action:sleep )=6hr 45min //suppose you want 6 hr 30min sleep,remove 2hr from 6hr30min so, that's 4hr30min, now set, global_total=global_current+4 and global_total_min= global_current_min+30. All Done! //NOTE: suppose you've changed default 120 min to 90 min than remove 90 min instead of 120 min if (global_total<24) {global_hour="{global_total,numberformat,00}"; } else {global_hour=global_total-24; global_hour="{global_hour,numberformat,00}"; } if (global_total_min<60) {global_min="{global_total_min,numberformat,00}";; } else {x=(floor(global_total_min/60)); global_hour=global_hour + (x); global_min=global_total_min-(60*x); global_hour="{global_hour,numberformat,00}"; global_min="{global_min,numberformat,00}"; }Last_night_sleep(optional)To track sleepAuto Alarm falseSKIPShortcut: Sleep infoThis flow is to track sleep. make sure you set the shortcut.Message Dialog: Your last night sleep was about {global_abc,numberformat,00} hour and {global_xyz,numberformat,00} minutes [Note: based on first alarm, which was on {global_first_alarm}, and sleep start time {global_sleep_on_hr}:{global_sleep_on_min}}