Sun time seems stuck on GMT

I’m in the New York timezone, GMT - 5 hours. I’m using sunrise and sunset for a trigger to turn lights on and off. The script set for 15 minutes before sunset is going off 5 hours early and the same for the one for 15 minutes after sunrise. The log entries for the lights say, “Turned on at 3:06 PM,” not at 8:06 PM. I think this tells me HA is aware of the proper time zone and is in sync with my time zone.

HA is on a Raspberry Pi, using HAOS. If it were Linux, I’d use ssh and check the time and change it or my timezone within the OS if needed, but I’m not sure how to do that with HAOS. Plus, again, HA knows what time it is. So HA knows the correct time and timezone, but the Sun integration does not.

How can I fix this so the sun integration sees the local time? (Also odd is it seems to be working for my latitude, but not the timezone or longitude, so it gets one right but not the other.)

Share your script.

How? With screenshots of my settings I used to make it?

I don’t know how to get to the full script in the settings file. Here’s the screenshot of the trigger part:

And here’s a screenshot of the trigger and here’s a screenshot of the trigger and the settings before it on the UI page:

Scripts don’t have triggers. That is an automation.

Use YAML mode to share the automation.

Have you checked that Settings → System → General has the correct time zone listed?

Time in Settings:
image

I wasn’t sure how to get to YAML mode (and didn’t want to deal with a huge configuration file!), but when I had the page open for the visual editor and went to File Editor, it came up to that config file. So here’s what I have:

  • id: ‘1659684431732’
    alias: House Night Lights On
    description: Turn on lights in the house for overnight
    trigger:
    • platform: sun
      event: sunset
      offset: -00:15:00
      condition:
      action:
    • type: turn_on
      device_id: 7a5e4505475cf4e05619135de2ccbfbd
      entity_id: light.micro_dimmer_41_4d_db
      domain: light
      brightness_pct: 30
      mode: single

Opps. Right. Started with a script. Forgot I ended up changing it to an automation.

When you paste code, use the code blocks option </> Not the quote option. Or do this.

But if that was constructed in the GUI editor, then I’ll trust that the formatting is correct.

So the only other thing to check is your system time. Go to Developer Tools → Templates and paste this in:

{{ now() }}

Does it show the correct time in the results to the right?

For example this is 6:13 pm:

Screenshot 2022-08-09 at 18-13-18 Developer Tools – Home Assistant

Yes, it does, but the output is interesting:

I set my units to imperial, but the temp is still in Celsius. Also, the time, as I said is correct. (Currently 11:40 AM.) However, note it says the sun rose 11 hours ago. That would be 12:40 AM, and it should be about 5:40 AM. So the system time is correct, but the sun time is off.

I was wrong about local sunrise. Here it was 6:21 AM, but when I check Greenwich, it is 5:28 AM. So it does seem as if it’s using data for the wrong time zone. I know sunrise changes depending on latitude, so I’m not sure which city it’s using for its location, but I’m still thinking it’s stuck in GMT.

I just restarted my system (using the Restart button on the upper right under Settings->System) to see if it made a difference. Now I get this:

Note local time is 13:56. small detail, but just after I restarted, and went to this page, I got a phone call and just got back to it to get a screenshot. When this first came up, it said the sun rose 10 seconds ago, which was less than a minute after I restarted. Before this, it was saying sunrise was between Midnight-1 AM. (I’m going by when I saw scripts execute - both the one set for 15 minutes before sunset and the one set for 15 after sunrise.)

I don’t know the system well, but this change in sunrise time to within a minute after the system restarted makes me think that somehow the Sun integration is using the system start as a reference for time.

Also on the Settings General page, have you set your location correctly?

We got a problem here. I set it a few days ago, before writing these automations. I made sure I saved it. I almost just replied, “Yeah, set it a few days ago.” But it has me in Amsterdam, just like before I changed it to my house in the US.

I tried changing the location, but all I can do is move the map to where I want. There’s no button to click “Save.” I went through Settings->System->General and it tells me to set it in Zone settings. There’s also an EDIT button there. If I got to Zone or click on EDIT it takes me to the same map and, either way, I can move the map to my location, but there’s nothing to click to save the setting. I moved to my location, exited the page, went back and it was in Amsterdam again.

I found, on this thread, that others are having trouble setting the location. I remember when I first set HA up, I had a serious problem with that as well. (It was in another install.) I’m not sure, but I think I finally had to resort to entering coordinates directly somewhere.

Okay, looks like it’s working. I was trying to move the map around to my house and click on my location or center it. There is nothing to indicate the way to specify location is to move the house icon. From my experience (finding this confusing twice) and from what I saw in that other thread, while this may seem straightforward, it’s not. Also, if you live on another continent, dragging that house icon around is a royal pain. It means zooming out 7-10 times, moving nearer your location, positioning the house roughly, then zooming in and, during the zoom-in process, repositioning the house multiple times to have it available but not directly over where you’re zooming.

I can see why a developer would think that’s a good way to set that, but it’s not clear and there are no prompts to explain it.

Yeah that does not sound like an ideal interface.

I just define it in YAML:

homeassistant:
  name: !secret name
  latitude: !secret home_lat
  longitude: !secret home_long
  elevation: 115
  unit_system: metric
  currency: AUD
  time_zone: !secret home_time_zone

Should I report that as a bug or feature request or something?

What file is that in? I checked in configuration.yaml and it’s not there.

You have to specifically put it there. This disables editing it via the GUI.

What is the filename?

configuration.yaml