Offset -8 hours from sun azimuth 180 degrees

Is there any way I can set up Home Assistant to turn on my plant lights 8 hours before the sun is at its highest position in the sky (azimuth 180 degrees)? I want to turn my plant lights on and off independent of daylight saving time.

Any help would be appreciated, thanks!

Thinking outside the box, template sensor in which you use UTC time rather than local?

Thanks for your reply @septillion!

I’ve already thought of that but to me it seems like a hack to use a separate time for a single automation so I was hoping that there would be a way to do it with azimuth and an offset. That being said, if there is no such way and that would work, I’m open for it. :slight_smile:

I have so far never used Home Assistant beyond the web interface and I guess there’s some config file editing involved in this, right? Is there an example of this or should I just go through the documentation?

Thanks again!

How about using this? Sun entity has a state attribute of azimuth.

I don’t really find it that hacky actually.

But yeah, you could use azimuth of sun.sun but I don’t think you would need the offset though. Isn’t 8 hours before azimuth 180 degrees always at 60 degree? Then you can just:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sun.sun
    attribute: azimuth
    above: '60'
condition: []
action:
  - device_id: ''
    domain: ''
    entity_id: ''

Haha! Well that is true but the 8 hours might change in the future. It would be more intuitive to me to input an hourly offset but it’s easy to convert it to an azimuth whatever the time might be so this should work perfectly. Thanks, I’ll try it out right away!

If you want it easy:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: template
    value_template: >
      {% set offset = -8 %}
      {{ state_attr('sun.sun', 'azimuth') >= ((offset / 24 * 360 + 180) % 360.0) }}
condition: []
action:
  - device_id: ''
    domain: ''
    entity_id: ''

Or even more flexible with an input helper:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: template
    value_template: >
      {% set offset = states('input_number.offset')|float %}
      {{ state_attr('sun.sun', 'azimuth') >= ((offset / 24 * 360 + 180) % 360.0) }}
condition: []
action:
  - device_id: ''
    domain: ''
    entity_id: ''

FWIW, sun.sun has a next_noon attribute that gives you the datetime the sun will be at it’s zenith :wink:

      {% set offset = states('input_number.offset')|float %}
      {{ as_datetime(state_attr('sun.sun', 'next_noon')) >= (utcnow() - timedelta(hours=offset)) }}

Edit: Use UTC

Yeah, that’s a great option as well! :smiley:

But how well will it work on the days DST starts/ends?

Good point. I’ve edited my post to use UTC only

1 Like

Thank you both for the introduction to templates and helping me look at Home Assistant beyond the GUI! I started off with the easy solution presented by you @septillion and it works well. I might take a look at input helpers and the next_noon attribute, that you mentioned @koying, later because I like the idea of using it and again it feels more intuitive to me.

Thanks again! :slight_smile:

1 Like