WebThingsIO / gateway

WebThings Gateway
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 336 forks source link

Gateway as master clock for connected things #1561

Open kgiori opened 5 years ago

kgiori commented 5 years ago

Lots of home appliances have a clock display and they are a pain to reset after daylight/standard time changes and power outages and due to incorrect clock "drift". For smart appliances that are connected to a Things Gateway, I would like the gateway to be the master clock coordinator. All my smart appliances should automagically show the same, correct, local time.

Some users might want to manually override the gateway or thing clocks. If so, UI clock override could be a config option.

dhylands commented 5 years ago

I know that zigbee also supports the notion of a time server and several of the devices that we use request the time from us. The zigbee adapter doesn't currently support the time server, but I would like to. To implement the time server functionality, the following information is required:

I believe that knowing the current timezone is sufficient and the DST and timezone seconds are available from the OS.

flatsiedatsie commented 5 years ago

See also: https://github.com/mozilla-iot/gateway/issues/1530

kgiori commented 5 years ago

Should we define a new webthing type of "TimeProperty"? or "ClockProperty"? Smart appliances with a clock display could be defined with a ClockProperty. And as @dhylands noted, some Zigbee devices want to query time, even though they may not have a display. For devices that don't do time queries, could rules be used to set device clocks using an event or action? Or should some other global setting cause the gateway to periodically broadcast a time event? Goal is to help IoT devices keep their clocks in sync.

mrstegeman commented 5 years ago

In general, we should probably just run an NTP server. The Zigbee adapter can pull from the local clock and forward the time out as necessary. Why reinvent the wheel?

mrstegeman commented 5 years ago

We can advertise this on the network via mDNS with a _ntp._udp service type record.

flatsiedatsie commented 5 years ago

For me this would be more about a UX to be able to set that clock to a desired time, and less about network devices getting that time?

It can be surprisingly difficult to know what time the Gateway thinks it is, and at least two users has issues with logging because the clock was set wrong. I was one of them, and I had to SSH to the Pi to change the clock/locale.

See this issue, for example: https://github.com/mozilla-iot/gateway/issues/1815

USER STORY

As a user I'd like to set the clock for the gateway via a UX.

Related: the MySensors adapter sends the time from the gateway to the devices in the MySensors network. In that context the Gateway already functions as the 'master clock'.

Fun times: clocktrouble