Haiku Time of day

Szerby

New Member
I am not a programmer really.
 
Can you give me a sample of how to check for time of day?
 
For example, I would like to be alerted if it is after 9pm and the garage door is left open.
 
Thanks!
 
Assuming its for a use like you mentioned, you want to do a scheduled check. There are different ways to do it, since we have all of the flexibility of JavaScript. But one way would be to check the date in onSyncStart:
 
ie.
 
 
Code:
function onSyncStart(forced, timestamp) {
    var date = new Date(timestamp);
 
    if(date.getHours() == 21 && date.getMinutes() == 0) {
        if(controller.zoneWithName("Garage Door").isNotReady) helper.sendNotification(controller, "Garage door left open!");
    }
}
You could also use a range check, but then you might want to use a var to store the last time the notification was sent so you don't constantly get these notifications every minute. Or you could make it check every hour:
Code:
    if(date.getHours() >= 21 && date.getHours() <= 0 && date.getMinutes() == 0) {
        if(controller.zoneWithName("Garage Door").isNotReady) helper.sendNotification(controller, "Garage door left open!");
    }
 
However if you want to check it when an event happens, then your check would be more like:
 
 
Code:
function onZoneNotReady(zone) {
    if(zone.name == "Garage Door") {
        var date = new Date();
 
        if(date.getHours() >= 21 && date.getHours() <= 7) {
            if(controller.zoneWithName('Garage Door').isNotReady) helper.sendNotification(controller, "Garage door opened after 9!");
       }
   }
}
 
Back
Top