Hi Taras,
Thanks for your reply. I thought you are on to something with elevation value. The configuration section had an elevation = 0 so, I changed it to elevation of my location. However, it did not change the sunset attributes values.
here is the result from template code you ask me. It seems right to me.
and here is the sunset attributes values.
There are 7 hours difference between UTC and Local time and I don’t think these times are in UTC. IF I subtract 7 hours from Dusk time it would 3:55 pm and Dusk in our place happens at 5:55 pm. if I subtract 6 hours that is close.
If we fix the attributes time then we should be ok to use Sunset and Sunrise trigger.
Your time zone is set to America/New_York which is 5 hours less than UTC (even says so in the template results you posted above, -05:00, which is UTC minus five hours). So why do you believe there should be 7 hours difference?
If the time where you live is actually UTC-07:00 then you have selected the wrong time zone.
Sorry my bad. You are right, it is 5 hours difference. So, we are back to square one. We know the trigger runs on UTC time for SUN attributes. Only option is to create a template to convert those attributes to local time and then added to trigger of automation.
I need a template to convert the attributes value to local time and apply offset in format of hh:mm and compare it with current time. If it is match then true and if not is then false
The two sensors are updated at the start of every day (midnight) and whenever Home Assistant is restarted or Template Entities are reloaded. I set the offset to +300 minutes but change it to whatever you require.
Create an automation that is triggered by the two sensors. The offset sunset sensor turns the input_boolean on and the offset sunrise sensor turns it off. Change the name of the input_boolean to whatever you require.
alias: example sunrise offset
- id: 'on'
platform: time
at: sensor.sunset_offset
- id: 'off'
platform: time
at: sensor.sunrise_offset
condition: []
action:
- service: "input_boolean.turn_{{ trigger.id }}"
target:
entity_id: input_boolean.whatever
in my original, I was thing of converting the time to local first then adding the offset butt in your formula you included the offset and conversion of time in on operation. So I just used subtraction and now the offsets are correct. Will see if the trigger happen on sunrise.
The funny thing is that I was looking at the Logbook and I saw this entry:
The time is sport on. And when I click on entry SUN, it shows this:
All times are in EST time. However in Automation it does not execute on the right time.
All I can tell you is that I have several automations that are triggered based on sunset and I also live in the Eastern time zone and all the automations trigger at the correct time.
The example I posted above is based on another example I provided for another user who needed the offset to be random (as opposed to fixed) every day. It worked for that user.
The UTC datetime shown in your screenshot, 2022-01-28T03:23:28+00:00 is 2022-01-27 22:23:28-05:00 in your local time (EST). Basically that’s today’s sunset time plus 5 hours (300 minutes) to produce 22:23 (EST). It’s currently 18:58 (EST) so it’s obvious why the automation hasn’t triggered yet.
If you want me to continue helping you, I need the information I requested in my previous post.
This UTC time: 2022-01-28T07:36:34+00:00
is the same as: 2022-01-28T02:36:34-05:00
In other words, 7:36 UTC is 2:36 EST and the trace shows the automation successfully triggered at the scheduled time.
Except the automation is being triggered by sensor.sunrise_offset. According to your screenshot, that sensor is not reporting today’s actual sunrise time. Post the sensor’s current configuration.
Sorry Taras,
I am confused. Are you saying that the SunriseOffset is in UTC time and not EST? The whole discussion was to convert next_setting attribute (which is in UTC) to EST time so Time trigger would execute on that time.
This is the code for sensor
That confirms my suspicion that you purposefully set back the time by 5 hours and explains why the automation triggered at 2:38 EST (instead of 7:38 EST or its equivalent of 12:38 UTC).
Respectfully, this entire issue appears to be due to your misunderstanding of how time is handled in Home Assistant, specifically time zones.
Petro has provided a clear explanation of what you have been misinterpreting.