Shutter Configuration: Using Sun and sunset/sunrise as Trigger

Hi there comming from FHEM, I’m trying to rebuild my shutter config, where I used the sunset / sunrise events to trigger the closure and opening. FHEM had a very nice overview where I was able to see when this Automation will be triggered next (of course only if this is predictable). In HomeAssistant I was unlucky to find someting like this. Does anybody know where to find these information?

i.e:
Automation: Shutter_Kitchen_Night next: 21:30:12

Kinds a lot

The normal sun sensor only works on current date, so it can’t show that, but there is an alternative sun sensor called sun2 that is so much better.

Unfortunately this Integration isn’t found by HACS ?!?

No, but the link provided the manual install.
It is quite easy, but a restart is required in the end.

I think I added it as a custom repro to HACS, so it updates automatically.

Yes I know, but this manual installation doesn’t work either, or maybe I’m too stupid for this. Copied the files manual into a new folder called sun2. Then restartet the whole HA. Still nothing can be found via Config → Integrations, nor (waht should make sense) under HACS.

This is an addon, not an integration.
It adds a functionality to HA that you can activate through your configuration.yaml

I have this in my configuration.yaml:

sensor sun2:
  - platform: sun2
    entity_namespace: Copenhagen
    latitude: 55.663
    longitude: 12.553
    time_zone: Europe/Copenhagen
    elevation: 3
    monitored_conditions:
      - sunrise
      - sunset
      - dawn
      - dusk

Sun2 is an integration, not an add-on. Add-ons are only supported by HAOS and Supervised installations and are for separate services, such as an MQTT broker.

That said, sun2 should work, and the files should go under your custom components directory. Is there anything in the log on startup? I would recommend installing it via HACS, just because it’s less of a hassle. Just make sure you remove the manually added files if you wish to take this route. You might need to go to HACS and use the “add custom repo” button on that page, and after that install it. Either way, you won’t see this integration under Settings → Integrations. That’s only for the built-in ones. You’ll either see nothing in the UI, or if you use HACS it will be under HACS’s integrations UI.

The built-in sun integration would be best for this use case (depending on how exact you’d like it to be): The sun integration gives you sunset and sunrise attributes for the next event, whereas sun2 gives you the values for the current day (reference: Sunrise time - #8 by 123). Depending on where you live, it might not differ that much (i.e. change that quickly).

EDIT: Fixed my reversal of the sunrise and sunset events for the two integrations.

Hi what I’d like to accomplish:

Setting the shutter closure to sunset. And if so, because sunset is varying over the year, to see what specific time it is for the next closure and the next opening. And because sunset for today and tomorrow are likely almost the same I could live with this minor inaccuracy.

So what is in the config right now and working the shutter closes at sunset and opens at sunrise, but I’m missing a display that tells me on my dashboard, closure will be at 10pm or so… Right now I have to guess :slight_smile:

You can add a markdown card to your dashboard.

Try this in your template editor (untested from my side):

Shutters will {{ 'close' if is_state('sun.sun', 'above_horizon') else 'open' }} at {{ state_attr('sun.sun', 'next_dawn') if is_state('sun.sun', 'above_horizon') else state_attr('sun.sun', 'next_dusk') }}.

I don’t know what your automation to open or close the shutters look like, but maybe you want to use the elevation attribute instead. This is all for the built-in sun integration, not the sun2 integration, but you should be able to adapt it.

You are correct.
I got it mixed up.
Sun2 is an integration, but without a GUI.

But sun2 will not just give you the next values.
It will give you yesterdays, todays and tomorrows values.

So maybe I’m describing my issue a bit to complicated. One of my configs looks like this:

alias: shutter_livingroom_night
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '3600'
condition: []
action:
  - device_id: d062c8872a828e2ba0d7feb997b6a44c
    domain: cover
    entity_id: cover.shutter_livingroom_low_speed
    type: set_position
    position: 0
mode: single

My question now is. When will this action be triggered. I’d like to see an actual timestamp. Because sunset + 3600 only means 1 hour after sunset, but is this 10pm or 9:45pm or 9:30pm ? That would be wonderful. So I’d like to achieve a view where to see when this automation will be triggered. :slight_smile: Maybe I am expecting to much but comming from FHEM, I had a direct overview with this information.

Kinds to you all for the help

I don’t think that’s possible, but you can make a template sensor that does the calculation. Give it the right device class of timestamp and the UI will interpret it correctly.

I’d use sun2 and then you can see the next values if you like and make it a trigger or condition or both. You can create a sun2 sensor for this pretty easily.

binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation:
          name: Sun Above Horizon
      - elevation:
          name: Sun Daylight
          above: 12

You can specify your own offset elevation in it and it will create a sensor and then you can see what time it will happen today, tomorrow or yesterday in its attributes as well.

Edit: corrected offset to elevation.

Could you point to the docs of sun2 where it says you can specify an offset?

To me it seems like this will do the trick:

{{ state_attr('sun.sun', 'next_dawn') | as_datetime + timedelta(hours=1) }}

I used the wrong words. You can specify an elevation. Typically though an elevation is similar to an offset except expressed in how high the sun is relative to the event. So if you check the elevation at a 3600 second offset and then use that in hte sensor, you get really close. If you really wanted the offset, you could create a template based on the sun2 attributes easily as well. You know when it will happen, you just add your offset.

Another thing to be careful of, the normal ‘sun’ sensor will always display the NEXT dawn. So if you use sun in a template and expect the current DAWN after it has happened, then you’re not getting it. You’re getting tomorrows.

The sun2 will give you what today’s was queried anytime between midnight to midnight instead. So the use case for both of these really need to be considered.

Here’s a good writeup for sun2.