Wrong Time - How do you sync the time?

I’ve scoured forums trying to fix this with no avail. My system time is off by an hour, and a few minutes. This of course throws off the time in HA. I’ve done everything I could find from changing international settings, updating ntp servers, etc. I thought I would be smart and move the Rpi a time zone over, but it still corrects itself to be an hour off. I’m at a loss.

Anyone run into this issue or have any ideas?

If the time is off by an hour, then it’s most likely a timezone issue.

You can check a few things. The first is what does the output of sudo ntpq -c pe show?

Next is what does the output of date and date -u show? The first should show your local time and timezone, the second the time in UTC (aka GMT). You can then check the UTC time against one of any number of web sites, or even a simple Google for what is the time in GMT.

Finally, did date display your local timezone? It should match a file in /usr/share/zoneinfo. For example, if you’re in California, you’d be using US/Pacific, if you’re in Moscow you’d be using Europe/Moscow. If you don’t know, just tell us the country you live in (or, if you’re in a country with multiple timezones, where you live - AFAIK that’s only Australia, USA, Canada, Russia, and Greenland).

Ok so I ran your commands.

sudo ntpq -c pe says connection refused.
date shows the correct time zone but is 1 hour and 4 minutes behind
date -u shows the time also an hour and 4 minutes behind UTC

If you’re getting connection refused then you’re not running NTP. You need to step the time, then start NTP:

sudo ntpdate -b pool.ntp.org
sudo systemctl enable ntp
sudo systemctl start ntp

When I run;
sudo ntpdate -b pool.ntp.org
I get a command not found. It seems the enabling works, but the start up fails. Here’s the log.

pi@raspberrypi:~ $ sudo systemctl enable ntp
Synchronizing state for ntp.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d ntp defaults
Executing /usr/sbin/update-rc.d ntp enable
pi@raspberrypi:~ $ sudo systemctl start ntp
Job for ntp.service failed. See 'systemctl status ntp.service' and 'journalctl -xn' for details.
pi@raspberrypi:~ $ sudo systemctl status ntp.service -l
● ntp.service - LSB: Start NTP daemon
   Loaded: loaded (/etc/init.d/ntp)
   Active: failed (Result: exit-code) since Thu 2017-05-11 06:56:32 MDT; 3s ago
  Process: 21922 ExecStart=/etc/init.d/ntp start (code=exited, status=2)

May 11 06:56:32 raspberrypi ntp[21922]: /etc/init.d/ntp: 30: /lib/lsb/init-functions: Syntax error: ";" unexpected
May 11 06:56:32 raspberrypi systemd[1]: ntp.service: control process exited, code=exited status=2
May 11 06:56:32 raspberrypi systemd[1]: Failed to start LSB: Start NTP daemon.
May 11 06:56:32 raspberrypi systemd[1]: Unit ntp.service entered failed state.
pi@raspberrypi:~ $

Looks like you’ve got an incomplete/broken install:

sudo aptitude reinstall ntp

or if that fails because the package isn’t installed:

sudo aptitude install ntp

Both commands failed. Any thoughts?

pi@raspberrypi:~ $ sudo aptitude install ntp
The following partially installed packages will be configured:
  bsd-mailx exim4-daemon-light ntp 
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 197 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.
Setting up ntp (1:4.2.6.p5+dfsg-7+deb8u2) ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Job for ntp.service failed. See 'systemctl status ntp.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript ntp, action "start" failed.
dpkg: error processing package ntp (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up exim4-daemon-light (4.84.2-2+deb8u3) ...
Job for exim4.service failed. See 'systemctl status exim4.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript exim4, action "start" failed.
dpkg: error processing package exim4-daemon-light (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of bsd-mailx:
 bsd-mailx depends on default-mta | mail-transport-agent; however:
  Package default-mta is not installed.
  Package exim4-daemon-light which provides default-mta is not configured yet.
  Package mail-transport-agent is not installed.
  Package exim4-daemon-light which provides mail-transport-agent is not configured yet.

dpkg: error processing package bsd-mailx (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 ntp
 exim4-daemon-light
 bsd-mailx
E: Sub-process /usr/bin/dpkg returned an error code (1)
Failed to perform requested operation on package.  Trying to recover:
Setting up ntp (1:4.2.6.p5+dfsg-7+deb8u2) ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Job for ntp.service failed. See 'systemctl status ntp.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript ntp, action "start" failed.
dpkg: error processing package ntp (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up exim4-daemon-light (4.84.2-2+deb8u3) ...
Job for exim4.service failed. See 'systemctl status exim4.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript exim4, action "start" failed.
dpkg: error processing package exim4-daemon-light (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of bsd-mailx:
 bsd-mailx depends on default-mta | mail-transport-agent; however:
  Package default-mta is not installed.
  Package exim4-daemon-light which provides default-mta is not configured yet.
  Package mail-transport-agent is not installed.
  Package exim4-daemon-light which provides mail-transport-agent is not configured yet.

dpkg: error processing package bsd-mailx (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 ntp
 exim4-daemon-light
 bsd-mailx

That’s your problem. Somehow you’ve got a broken install. Did you start with Hassbian, or Raspbian and then install HA? Your best bet at this point is probably a Raspbian forum, where there’ll be many folks available to walk you through fixing this quickly.

Otherwise, try removing exim:

sudo dpkg -r exim-daemon-light exim4-config exim4-base

Then add something else (if you’re not using exim and sending/receiving email):

sudo aptitude install dma

Or, if you were planning on using this is a mail server, reinstall exim4:

sudo aptitude install exim4

Yeah I started with Raspbian and then used the AiO installer last year. I haven’t had a problem until recently so I’m not really sure what happened. That or I just haven’t noticed >.<

I really appreciate your help this far. I’ll reach out in the Raspbian forum before I do clean install.

You might find that removing exim and installing dma fixes it. You’ll know when sudo aptitude update; sudo aptitude full-upgrade works and doesn’t error.

Even when trying with dma, it fails right when it hits Ntp pretty much giving the same error.

What’s the error? What if you just remove all the exim components and bsd-mailx?

I can’t get the Pi to boot anymore. I took the SD card out and put it in my PC and I can’t get it to read correctly. I think the SD might have crapped out on me.

Could be the original problem of all of this. I’ll grab a new card and do a clean install. I had some other weird issues so a clean start isn’t the worst of ideas!

Thanks for all of your help. I expect NTP to work after I reinstall haha.

I ordered a DS3231 RTC module (1 euro). Install it like this: https://translate.google.nl/translate?sl=nl&tl=en&js=y&prev=_t&hl=nl&ie=UTF-8&u=https%3A%2F%2Fraspberrytips.nl%2Fds3231-rtc-raspberry-pi%2F%23more-1631&edit-text=. Works like a charm.

I also have problem with time. “date” shows Thu 11 May 23:02:46 EEST 2017 but actual is 25th and time 21.22
Any ideas? I tried changing servers in ntp.conf but no success.

Unfortunately, I believe my problem was that my SD card was failing and lost some crucial files for NTP. The best advice I can give is below from Tinkerer. Try reinstalling NTP and if it fails, check the logs and see what is preventing it from installing. My card got bad enough to where it won’t boot anymore. So I’m on to a new card and fresh installs.

When the date is too far out, NTP won’t correct it automatically. That’s deliberate.

You need to set it roughly correctly, which you can do by:

sudo aptitude install ntpdate
sudo service ntp stop
sudo ntpdate -b pool.ntp.org
sudo service ntp start

The ntpdate command force steps the time to match that of the server found at pool.ntp.org.

2 Likes

check the timezone in the home assistant configuration file. Mine was set to central when I am in eastern

Thanks, that fixed it.

A post was split to a new topic: Hass.io wrong timezone