How to set time?

Hi!
How do I set the tiem i my Home Assistant OS 8.1?
I have the correct values for timezone and location (using GUI), but the time is offset by about 15 minutes and I can’t find a way to correct it.
Running on Pi4, getting time error while trying to add Tuya integration. The time is really about 15 minutes off, it’s not a wrong report from integration.
I just could not find where to set HAS-OS time or even set ntp servers to use.

HA gets its time from the underlying hardware. Sounds like the time on your RPi is not set correctly. Have you checked it?

How do I do that?
I’m using Home Assistant OS, can’t access SO directly, just that CLI from HASS and doesn’t help too much. After setting time manually in this CLI (date -s hour:minute), after a few seconds, it’s back to wrong time.

HAOS uses systemd-timesyncd for NTP. Unfortunately the dbus interface of this service has no way to set the NTP server so its not possible for the CLI or Supervisor to provide an option to set this at this time.

What happens instead is first HAOS tries to use the NTP server provided via DHCP from your router. If one is provided it uses that and uses time.cloudflare.com as a fallback NTP. If an NTP server isn’t provided via DHCP then it just uses time.cloudflare.com.

Although I will note that this answer depends a bit on how old your system is. If its new then this is the behavior you should be seeing. If you’ve had it running for a while and been updating it then you might still have the old configuration for timesyncd which is this:

[Time]
NTP=time.cloudflare.com
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org

I would think if you had your router provided an NTP server via DHCP it would run the script to rewrite this to the new config based on that. But tbh I’m not sure. Personally I still see the old config on my system.

TL;DR - Provide an NTP server via DHCP if you want to exert control over this. Otherwise just make sure time.cloudflare.com isn’t blocked on your network. Actually the latter is a recommendation regardless since it is always at least the fallback NTP server.

1 Like

NTP provided by DHCP willl work even using static IP configuration is HAOS? :thinking:
Not static IP in DHCP server, but in Home Assistant configuration (set from GUI too).

Hm good question. I think in that case its just going to use time.cloudflare.com. But that seems like somewhere supervisor should have an option, I might have to look into that. @agners do you know what happens here?

I’d assume that NetworkManager only invokes a DHCP client when automatic network assignment is enabled. So yeah, I guess that only works with DHCP IP address assignment.

That said, if you configure your DHCP anyways, you might as well add a static assignment via MAC address. Then you can leave it on automatic on HA side and make use of the NTP server assignment :sunglasses:

Hi Guys,

I’m a UK based user of Home Assistant. my system is running on a RPi4 with external SSD and is plugged in to a LAN cable to my router. I have assigned to a static IP via the Router internal static route function.

So on to “How to set time” (in Home Assistant). I set up an automation yesterday to boost my hot water at 00:31 for the Cheap rate electric. It comes on for 1 hour then turns off. This morning I checked the logs and see that it came on at 23:31 (before cheap rate started). So then I started to check my HA time settings and the logs are reporting in UTC so there is my problem of the system time being 1 hour before my actual GMT(London) time zone.
Below is the History of the hot water temperature and as I’m checking the log you see I’m at the end of the history line and it shows me UCT rather than the actual location time seen on my PC.

I then checked the system settings and see this:

To me, this indicates that the HA tine would be UTC +1 (London) if I did not have something in the yaml configuration overriding that. I checked in my ‘configuration.yaml’ but there is no time settings that I can see. I then searched on the forum and found this to check my system time in the Developer template:

{{ now().tzinfo }}

So now I’m stuck and out of ideas within my current knowledge, is there another place to set my OS (RPi 4) time zone to GMT(Europe/London) and if so how can I do that through the HA Command line terminal?
Or where and how can I remove the configuration overrides and revert (reset) back to the HA System settings?

Thank you in advance for some guidance to this problem.

@angusc In your configuration.yaml do you have this at the top.


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

In your developer tools again on template tab put this (this is every time function

{{ now() }}
{{ now().astimezone() }}
{{ utcnow().astimezone() }}
{{ now().now() }}
{{ now().today() }}
{{ now().utcnow() }}
{{ utcnow() }}
{{ now().tzinfo }}
{{ now().astimezone().tzinfo }}
{{ utcnow().tzinfo }}

You can see what your time is set for

Regarding: “Editor disabled because config stored in configuration.yaml.”

Do you have any of these In your configuration.yaml?

  name: Home
  latitude: 12.3456
  longitude: 12.3456
  elevation: 99
  unit_system: metric
  time_zone: Europe/London

If so, comment out all fields that you see in the UI Editor and restart HA

#  name: Home
#  latitude: 12.3456
#  longitude: 12.3456
#  elevation: 99
#  unit_system: metric
#  time_zone: Europe/London

1 Like

Hi Blacky,

Thank you for your support, here is my current configuration.yaml, it’s probably a bit mixed up as I have added to it as and when I found new bits of code:

homeassistant:
  currency: GBP
  external_url: !secret ha_external_url
  packages: !include_dir_named packages
  customize: !include customize.yaml

  allowlist_external_dirs: 
    - /config/www/cam_snaps

# Media Directories
  media_dirs:
    media: /media

# Homeassistant base location
  name: Home
  latitude: 52.14xxxxxxxxxxxx
  longitude: 0.10xxxxxxxxxxxxxxx

ffmpeg:

#Nuba Casa
cloud: !include cloud.yaml

# Enable Sensor History & Purge History

recorder:
  purge_keep_days: 60
  auto_purge: true
#  exclude:
#    entities:
#      - sensor.consumption_electricity_counter
#      - sensor.consumption_electricity_gauge
#      - sensor.exporting
#      - sensor.exporting_mqtt
#      - sensor.importing

history:
#recorder:
#  purge_keep_days: 62
#  include:
#    entity_globs:
#      - sensor.solcast*

# Enable the Default Logger
logger:
   default: info
   logs:
    custom_components.webrtc: debug
    default: error
    homeassistant.components.webhook: debug
    homeassistant.components.recorder: debug

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Home Zone override.......
zone:
  - name: Home
    latitude: 52.xxxxxxxxxxxxx
    longitude: 0.10xxxxxxxxxxxx
    radius: 120



# Themes
frontend:
  themes: !include_dir_merge_named themes
  extra_module_url:
    - /hacsfiles/lovelace-card-mod/card-mod.js
    - /local/card-mod.js

#   refreshes lovelace dashboard in companion app
    - /local/custom.js

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


This is the output from the developer template actual time in the UK when the bellow template was initiated was 14:14:

I edited out the Home: lines as you suggested but after a restart the time is still reporting UCT rather than actual UK time:

@angusc Try this now I can see your current configuration.yaml. I put a “#” in to comment out all fields

from this

homeassistant:
  currency: GBP
  external_url: !secret ha_external_url
  packages: !include_dir_named packages
  customize: !include customize.yaml

to this

homeassistant:
#  currency: GBP
  external_url: !secret ha_external_url
  packages: !include_dir_named packages
  customize: !include customize.yaml

from this

# Homeassistant base location
  name: Home
  latitude: 52.14xxxxxxxxxxxx
  longitude: 0.10xxxxxxxxxxxxxxx

to this

# Homeassistant base location
#  name: Home
#  latitude: 52.14xxxxxxxxxxxx
#  longitude: 0.10xxxxxxxxxxxxxxx

from this

# Home Zone override.......
zone:
  - name: Home
    latitude: 52.xxxxxxxxxxxxx
    longitude: 0.10xxxxxxxxxxxx
    radius: 120

to this

# Home Zone override.......
#zone:
#  - name: Home
#    latitude: 52.xxxxxxxxxxxxx
#    longitude: 0.10xxxxxxxxxxxx
#    radius: 120

check and restart HA

you should be able to set the time now.

1 Like

Thanx! that allows me to set the London time by updating the map location by dragging and dropping the pin back to the UK. 4 years ago when I switched from ‘Openhabian’ to ‘Home Assistant’ I was setting up the RPi from France so it has always had the wrong location on the map until I added the location GPS in to the configuration.yaml now I think I have managed to change it the correct way. I’m currently out so will check from my UK PC shortly and let you know.

@angusc

No problem,

I don’t know what temp sensor you are using but you may need to reload it as well if it still on UCT time.

Hopefully you won’t need to uninstall and reinstall it.

1 Like

Thank you @Blacky! Your hints regarding time/locale settings fixed my issue too. Although, not explicitly defined in the configuration.yaml file, I was able to “fix” the issue by playing around with the settings (Settings > System > General) and after a reboot my date is no longer 2022-04-12 (it’s properly set to 2022-08-31).

1 Like

Unfortunately, this didn’t stick. I then tried to reload a backup to a new image but it still had the same issue. The solution here works after reboot. However, it needs to be done every time (it’s not a permanent fix).

Hey! Hoping you can help.

I am having an issue of time drift where I have to completely reboot home assistant once a week to keep it somewhat accurate. Tested ping.cloudflare.com and it responds - so it’s not blocked. Any idea how to fix this?

Hello guys,

I have a instalation of HAOS in a RP3, and the time has drifted 41 minutes, and no matter how man times I reboot it, set the NTP (42) via DHCP, it simply does not correct this time. Could anyone please give me a hint on how could I solve it?

I´m pretty sure it´s not a locale issue, as it´s not a round time diference.

THanks,

I use Chrony to sync the clock of HA, i was struggeling with syncing the clock to as i have a internal ntp server and ha does want to sync the clock with google ntp’s, with chrony you can set your own ntp servers and set it to sync HA server also GitHub - hassio-addons/addon-chrony: chrony - Home Assistant Community Add-ons

cheers

1 Like

every part of HA (sensors, automations etc) report the correct time (CET), except host log, which looks like showing UTC…

is that ok? how can I set it to the same as HA?

That is normal