After a power failure in the whole house, the Time and Date gets confused! That is, totally wrong.
When I do a normal reboot or power OFF/ON cycle, the date is set correctly.
I believe, the problem is, when OpenHAB wakes up after a power failure, the internet connection is not yet available and the time does not get set.
I would expect the system to retry this more than once? Or it doesn’t?
The Raspberry Pi doesn’t have a battery for some kind of hardware clock (like PCs or Laptops have). That’s why, after disconnection the PI from power (not only power failure, but simply pulling the USB-plug), the PI boots without a time.
I’m curious, because normally the PI distributions always come with an NTP preconfigured, because of this!
So, “totally wrong” means the time has an offset of some hours? or is it some time around 1970?
if it’s only off for some hours, your timezone is not configured, and you should go like this:
sudo raspi-config
Select Internationalisation Options
Select I2 Change Timezone
Select your Geographical Area
Select your nearest City
Select Finish
Select Yes to reboot now
So, if it doesn’t update, you need to install the NTP Client.
If you don’t use openHABian (which is a pretty perfect solution for running OH2 on a PI and comes also preconfigured with a NTP client), you must configure NTP for yourself (depending on the distro).
For the Raspbian distro it’s pretty straight forward:
sudo apt-get install ntp
that’s it - you don’t need to do anything more.
But if you have an NTP Server in your home and would like to use this one (FritzBox! for example), you can do that:
sudo nano /etc/ntp.conf
in there you can then edit the servers or add yours - and your PI should have the right time from now on.
The NTP daemon handles the update cycle for itself. There’s no need to define the cycle, so probaly your timeservers are not located ideally for your location.
You can pick your nearest here: NTPPoolServers < Servers < Network Time Foundation's NTP Support Wiki and change it in /etc/ntp.conf as described above.
…
If you still feel the need to configure the cycle for yourself, you can use the minpol and maxpol Setting in /etc/ntp.conf as described in man ntp.conf:
minpoll minpoll, maxpoll maxpoll
These options specify the minimum and maximum poll intervals for
NTP messages, in seconds as a power of two. The maximum poll
interval defaults to 10 (1,024 s), but can be increased by the
maxpoll option to an upper limit of 17 (36.4 h). The minimum
poll interval defaults to 6 (64 s), but can be decreased by the
minpoll option to a lower limit of 4 (16 s). These option are
valid only with the server and peer commands.