Easier Day Night Detection

I created this so that I would have an easier way of triggering day and night events in my automations, once this is set you can use your input select instead of using sun as a trigger or condition

To use this you have to create a input select for this with 2 options the first ‘Day’ and the second ‘Night’, ensure they are spelt the exact same way with no spaces at the beginning or end. Once that is done add it to the blueprint select your offset times and your done

This is a very basic blueprint, though it has been much easier for me using this to detect day and night then any other way

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.


blueprint:
  domain: automation
  name: Easier Day/Night Detection
  description: An easier way to detect day and night detection
  input:
    input_select_day_night:
      name: Input Select
      description: Add a input select helper here
      selector:
        entity:
          domain: input_select
    sunrise_offset:
      name: Sunrise Offset
      description: Set the elevation of the sunrise see link for specific values https://gml.noaa.gov/grad/solcalc/
      default: 0
      selector:
        number:
          max: 10
          min: -10
          unit_of_measurement: °
          mode: slider
          step: .1
    sunset_offset:
      name: Sunset Offset
      description: Set the elevation of the sunset see link for specific values https://gml.noaa.gov/grad/solcalc/
      default: 0
      selector:
        number:
          max: 10
          min: -10
          unit_of_measurement: °
          mode: slider
          step: .1

trigger:
  - platform: numeric_state
    entity_id: sun.sun
    below: !input sunset_offset
    attribute: elevation
  - platform: numeric_state
    entity_id: sun.sun
    above: !input sunrise_offset
    attribute: elevation
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: sun.sun
        attribute: elevation
        above: !input sunrise_offset
    then:
      - service: input_select.select_option
        data:
          option: Day
        target:
          entity_id: !input input_select_day_night
    else:
      - if:
          - condition: numeric_state
            entity_id: sun.sun
            attribute: elevation
            below: !input sunset_offset
        then:
          - service: input_select.select_option
            data:
              option: Night
            target:
              entity_id: !input input_select_day_night
mode: single

Updated to use sun’s elevation

Fair enough, but you really should use sun’s elevation rather than a time offset.
Depending on the season, a fixed time offset will give you different results in terms of luminosity.

1 Like

Ok thanks for letting me know, I just had a read of the link, testing it out in an automation, I’ve only been using home assistant for a month so never knew about the Sun elevation, I had been using homey for the past 5 years, but as I dig deeper down the home assistant hole I’m realising that it is far superior then homey