Is there a time zone issue?

Hi,

In a script I added a time check to stop a fan in the evening so that it would not bother anyone sleeping. Some time later I noticed that the time check stopped in the middle of the day thinking it was midnight. Looking at the log file you can s ee that at 14:55 local swedish time the script thought it was 23:59 and turned off the fan.

app:8462024-07-24 14:55:56.275debugThe time is 2024-07-24T23:59:00.000+0200 which means the restriction for keeping the fan on has been readched. Turning fan off

I am fairly new to Groovy so I may have done something unintentionally but I don't think so. As far as I can see I have not used any intentional altering of the time zone. These are the two methods that control the time restriction:

// ----------------- Time limit for the App to be active ------------------------------------------------

def isActiveTimeApp() {
    
//    log.info "Evaluating isActiveTimeApp()"
    
    def now = new Date()
    def startTime = timeToday(settings.appActive_startTime_v)
    def endTime = timeToday(settings.appActive_endTime_v)
    timeWindowCheckV = now.after(startTime) && now.before(endTime)
    log.debug "isActiveTimeApp: App Roof fan start time window checked: ${timeWindowCheckV}"
    return now.after(startTime) && now.before(endTime)
}

// ----------------- Time limits for forced ventilation -------------------------------------------------

def isActiveTimeForcedVent() {
    
//    log.info "Evaluating isActiveTimeForcedVent()"
    
    def now = new Date()
    def startTime = timeToday(settings.autoForcedVentilation_startTime_v)
    def endTime = timeToday(settings.autoForcedVentilation_endTime_v)
    timeWindowCheckVentV = now.after(startTime) && now.before(endTime)
//    log.debug "isActiveTimeForcedVent: Forced ventilation start time window checked: ${timeWindowCheckVentV}"
    return now.after(startTime) && now.before(endTime)
}

Looking at the hub details the time zone seems to be correct set up.

image

I have altered the code now to compensate for this situation but I saved the original app script if you want to reproduce the situation.

Cheers,

Might also want to check the latitude and longitude settings on the hub. I've seen those give different results if they and the time zone don't agree.

1 Like

i remember bumping my head on a datatype issue in my code - I thought I was getting date/time but wasn't.. or viceversa...

1 Like

You might want to include location.timeZone in the calls to timeToday, like this:

def startTime = timeToday(settings.autoForcedVentilation_startTime_v, location.timeZone)

Dealing with time is such a pita.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.