Time - No internet reference

Hello all,

I live in an area that has no internet service. My only option is to use an ethernet bridge to my hotspot on my cell phone. So, basically, my system cannot get NTP info unless I’m home AND my hotspot is on.

Is there a way to update system time when there is internet available? Or possibly a way to sync it with my cell time? I really dont want to depend on being “connected” for a correct time reference.

Another potential option - buy a USB GPS dongle and use that to give your computer an accurate time reference. No internet required, though you will of course need to see GPS satellites at some point during the day/week to maintain accurate time.

I’m not the linux expert, but if you just configure ntp will it not sync as soon a network connection is detected?

Otherwise use the network binding to detect if your phone & hotspot is active and then use the exec binding to start ntp

How would I see of the hotspot is active? I only have 3 channels available for the phone, and none of them have anything to do with operations on the phone itself.

My understanding:
If hotspot is enabled, your phone will act as a wifi access point. If hotspot is disabled, your phone will not start the wifi access point.

Therefore the assumption, if OH can connect to the wifi and ping your phone, the hotspot is enabled.

I appreciate the reply Matthias. I have been using OH since 1.x, but i can honestly say that I have not had the time to invest in learning OH3… How would I go about checking to see if openhab is connected to the internet? I know how to find the phone, but looking in the rules, I see nothing about how to tell if OH is connected to wifi (actually plugged directly into router…I know with the network binding

None of this has anything to do with openHAB though, does it?

  • You have an always on (?) computer
  • The time is set on that computer
  • Without further input, that time will slowly drift away from reality (slowly slowly)
  • One in a while you’re around and will activate your WiFi hotspot
  • Your computer will go ‘yes please’ (automatically) and re-connect to that WiFi hotspot
  • Amongst other things, your computer will update its time after connecting to an NTP server

Do any of the steps above not work in your setup?

I have a pi that is always on, yes. It does not have an ntp server on it; should i install one?

I would advise you the same thing as T. At work I have setup a GNSS (gps) receiver in a mobile unit with lots of servers doing time critical stuff. The GNSS is connected to a raspberry pi. The pi has NTP service installed and all computers on that local LAN get their time from the pi. We also have an IO line for PPS (pulse per second) but for if you don’t mind the clock to be one second off then don’t worry about that.

Here is a good reference:
Building a Raspberry-Pi Stratum-1 NTP Server (satsignal.eu)

Another idea could be to setup an NTP server on your phone. And letting the openhab host sync it’s time with your phone. Never done this but a quick google search gives me this:
Time Server App - Apps on Google Play

If you don’t like any of the above solutions and want to do it with OpenHab, you could install the network/ping binding and let it check for internet connectivity to an ntp server. That could set an item switch to ON which you can use to run a rule. I don’t know if you can interact with your host system by using the rule but I do know that it’s possible to force the NTP service installed on windows and linux hosts to do a time sync.

Sounds like good solutions…think ill try option 2. Thank you much sir!

1 Like

Most OS for raspberry pi should have the NTP client installed by default and have set the NTP server address to which they sync their clocks to some kind of pool.

I can’t remember exactly but I think that client also allows to setup an NTP server. But that’s only necessary if you are going to attach a GPS receiver.

No, your Pi will connect to an external NTP server by itself. That’s all usually configured by default by the Raspberry OS. You shouldn’t have to do anything other than provide the hotspot.

Awesome. Thanks again

Should I then configure the NTP binding to connect to localhost?

What for? Your OP doesn’t mention openHAB at all? What info are we missing that makes you want to have openHAB involved in this?

I am using OH for gardening control. I need to base rules on actual time.

Openhab uses host system time to trigger rules, so you don’t need to do anything with the ntp binding.

1 Like

Ok, so I can make sure Im on the same page. The pi will automatically update its time when it connects to my hotspot, otherwise it will keep time between. No need for the ntp binding at all?

1 Like

That sounds about right. Make sure that the pi really has internet access when it’s connected and that NTP has a target that it can reach. Then it mostly depends on polling intervals. But you could force it using the command line just to test if your clock is set correctly.

1 Like

Sounds good. Thank you again

1 Like