Author Topic: How to set a local time server?  (Read 819 times)

Offline therealdb

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-0
  • Automate all the things!
How to set a local time server?
« on: October 11, 2018, 02:43:28 am »
Hi. I have a very flaky internet connection: sometimes it's now working good and if the Vera reboots, I have problems with time.

I found a couple of very old posts about changing to a local NTP server, but I'm not sure if that's the right direction. I have a synology NAS, so I think I'm covered. I can also install it on my local ubuntu server.

I'd prefer a way to automatically re-install after a firmware upgrade.

Any help is appreciated. Thanks.
Vera Edge EU, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (2), Nest (3), Home Server running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station, Sonoff TH & more

Offline reneboer

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1418
  • Karma: +80/-30
Re: How to set a local time server?
« Reply #1 on: October 11, 2018, 06:02:35 am »
Hi,

I used these instructions to set one of my Vera's to a local PI running a NTP server.

http://forum.micasaverde.com/index.php/topic,33038.0.html

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline therealdb

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-0
  • Automate all the things!
Re: How to set a local time server?
« Reply #2 on: October 11, 2018, 06:16:22 am »
Thanks Rene, I think I made it.
Vera Edge EU, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (2), Nest (3), Home Server running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station, Sonoff TH & more

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +71/-24
Re: How to set a local time server?
« Reply #3 on: October 29, 2018, 10:38:34 pm »
Sorry, might be a bit off topic but I have been digging pretty deep into the OpenWrt OS of my vera plus over the past few days and have discovered a number of forgotten scripts.
As I found out, during boot up, the vera intervenes on its time with 5 different scripts!!!!!

First openWRT has an internal script which checks your entire file system and determines the latest updated file date and sets the time to that date. It is actually very well designed by openWRT developers.
"/etc/init.d/sysfixtime". It is actually the first script the init.d runs.
Second, this script is from Mios, is run a little later in the boot sequence "/etc/init.d/mios_fix_time" which checks whether the unit has a battery and then updates the system time to a time saved in a file when the vera shut down. The problem is that file may not be saved if you brutally unplugged it or in case of power outage. If it was saved it will take the previous time and just add 1 minute as the supposed time it takes to reboot. It also updates to that time only if it determined that it got its time from the internet through a temporary file ("/tmp/.time_synced") created by a script which seem to no longer exists on my machine, otherwise by default it will reset the time to midnight Jan 1st 2000 if none of the conditions above occur. This is a little convoluted script which is overkill and does not work very well.
The third one is from the OS through the ntpclient which is run as a service and loads just before the cmh Luup engine starts.
The fourth one is through another OS service: ntpd, so there are actually 2 ntp services running and updating the time.
The fifth one is within the cmh Luup engine itself which calls an obsolete ntp sync program: "rdate" still residing on the vera through the "/usr/bin/sync_time.sh" script. On my Vera Plus, this script fails because it requires a "function.sh" file which is not where it thinks it is. The file is in /lib instead of /etc.

Overall this is a mess... When I reboot the vera I get a reboot time in my logs of 2min after Jan 1 2000 because my temp file never has the flag to indicate it got its time through an ntp server. I suspect it is because it is should be coming from rdate which is probably not working. I then get a Luup reload time which is accurate since it has been synced with ntp.

I have now killed 2 of the 5 scripts calling for the system time update... essentially the 2 mios ones and I am getting better time accuracy upon reboot.
« Last Edit: October 30, 2018, 12:02:30 pm by rafale77 »
openLuup (97 devices, 134 scenes, 20 apps) controlling HomeAss + VeraPlus (138 zwave nodes, 8 Zigbee nodes, 205 devices, 20 scenes , 2 app) Bridged to Homekit and Alexa. VeraPlus ExtRooted!

Offline therealdb

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-0
  • Automate all the things!
Re: How to set a local time server?
« Reply #4 on: October 30, 2018, 11:24:12 am »
Have you opened a ticket? I think they can try to improve this particular piece of their architecture and, we hope, to just let us specify a time server in the UI.
Vera Edge EU, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (2), Nest (3), Home Server running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station, Sonoff TH & more

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +71/-24
Re: How to set a local time server?
« Reply #5 on: October 30, 2018, 12:04:38 pm »
Have you opened a ticket? I think they can try to improve this particular piece of their architecture and, we hope, to just let us specify a time server in the UI.

No, I haven't. I have been frustrated with opening tickets and seeing no change in the OS related to my tickets so I kind of took upon myself to now modify the vera myself. One other thing I have done is preventing the vera from rebooting when it loses internet connection or even network connections and have been testing that...
openLuup (97 devices, 134 scenes, 20 apps) controlling HomeAss + VeraPlus (138 zwave nodes, 8 Zigbee nodes, 205 devices, 20 scenes , 2 app) Bridged to Homekit and Alexa. VeraPlus ExtRooted!

Offline therealdb

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-0
  • Automate all the things!
Re: How to set a local time server?
« Reply #6 on: October 30, 2018, 01:29:12 pm »
I can relate to your frustration, but maybe now they're more open to feedback than in the past.

I'm curious about your solution to prevent reboot with no internet. If you don't mind sharing, it could be helpful to me, since my internet connection is very unstable (it's a wifi bridge - long story, they forgot to cover my house, so fiber will come later in 2019 - I hope)-
Vera Edge EU, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (2), Nest (3), Home Server running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station, Sonoff TH & more

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +71/-24
Re: How to set a local time server?
« Reply #7 on: October 30, 2018, 02:06:49 pm »
Sure, I will share that once I confirm that it works. I've been peeling the onion and I wish the box was not so convoluted and buggy. It is carrying a lot of legacy code, some of which is conflicting with newer code or is buggy.
openLuup (97 devices, 134 scenes, 20 apps) controlling HomeAss + VeraPlus (138 zwave nodes, 8 Zigbee nodes, 205 devices, 20 scenes , 2 app) Bridged to Homekit and Alexa. VeraPlus ExtRooted!

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1003
  • Karma: +23/-31
Re: How to set a local time server?
« Reply #8 on: October 30, 2018, 03:19:20 pm »
I watch your threads a lot like taking Vera off the grid. Good luck. Maybe you could be a 300/hour contractor for them.  :)

Sent from my VS995 using Tapatalk