Update Hub Time via driver

With the new functionality in 2.1.5, here is an example of a driver than can update the hub time by calling a server:

metadata {
	definition (name: "World Clock API", namespace: "anonymous", author: "anonymous") {
		capability "Polling"
	}
}

def installed() {}
def updated() {}
def parse(String description) {}

def poll() {
    // Call world clock api to get current time and set hub time based on that.
    httpGet("http://worldclockapi.com/api/json/utc/now") { resp ->
        def epochTime = (resp.data.currentFileTime / 10000 - 11644473600000L)
        location.hub.updateSystemTime(new Date(epochTime.toLong()))
    }
}
7 Likes

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