Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Home Assistant Sun2 Sensor

License

NotificationsYou must be signed in to change notification settings

pnbruckner/ha-sun2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sun2 Sensor Sun2 Sensor

Creates sensors that provide information about various sun related events.

Follow the installation instructions below.Then add one or more locations with desired sensors either via YAML, the UI or both.

Installation

With HACS

hacs_badge

You can use HACS to manage the installation and provide update notifications.

  1. Add this repo as acustom repository.It should then appear as a new integration. Click on it. If necessary, search for "sun2".

    https://github.com/pnbruckner/ha-sun2

    Or use this button:

    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

  2. Download the integration using the appropriate button.

Manual

Place a copy of the files fromcustom_components/sun2in<config>/custom_components/sun2,where<config> is your Home Assistant configuration directory.

NOTE: When downloading, make sure to use theRaw button from each file's page.

After it has been downloaded you will need to restart Home Assistant.

Versions

This custom integration supports HomeAssistant versions 2023.4.0 or newer.

Services

sun2.reload

Reloads Sun2 from the YAML-configuration. Also addsSUN2 to the Developers Tools -> YAML page.

sun2.get_location

Responds with the current location configuration options (latitude, etc.) of the specified location.Takes just one parameter,location, which is the name of the location, and is also the name of the corresponding integration entry.

sun2.update_location

Updates one or more parts of the location configuration options of the specified location.Takes one required parameter,location. (Same assun2.get_location service.)Can also take location parameters (latitude,longitude &time_zone), which if any are specified, they must all be specified.Can also take observer elevation parameters (obeserver_elevation).These parameters are the same as specified below in the YAML configuration section.

Configuration

One or more "locations" can be added for this integration.Each location is defined by a set of parameters (latitude, etc.)Sensors will be created for each location that provide sun related data for that location.A location can be added either via the UI or YAML.

To add a location via the UI, you can use this My Button:

add integration

Alternatively, go to Settings -> Devices & services and click the+ ADD INTEGRATION button.Find or search for "sun2", click on it, then follow the prompts.

The remainder of this section defines the list of YAML configuration options for each location.

KeyOptionalDescription
unique_idnoUnique identifier for location. This allows any of the remaining options to be changed without looking like a new location.
locationyes*Name of location
latitudeyes*The location's latitude (in degrees)
longitudeyes*The location's longitude (in degrees)
time_zoneyes*The location's time zone. (See the "TZ database name" column athttp://en.wikipedia.org/wiki/List_of_tz_database_time_zones.)
observer_elevationyesWhat affects sunrise & sunset as definedhere
binary_sensorsyesBinary sensor configurations as definedhere
sensorsyesSensor configurations as definedhere

* These must all be used together. If not used, the default is Home Assistant's location, time zone & name configuration.

Observer Elevation

The easterly sun events (sunrise, dawn, etc.) and westerly sun events (sunset, dusk, etc.)can be viewed at either the horizon, or at the top of some obstruction, such as a mountain.(For more details, seeEffect of Elevation.)This configuration option describes which apply at the specified location.

There are two basic choices. The first is that the sun events are seen at the horizon in both directions.In this case, a simple number may be given which defines the observer's elevation aboveground level (not sea level) in meters.If this option is not specified, then the elevation from the system's general configuration will be used.

NOTE:Settings -> System -> General -> Elevation is defined as "Altitude abovesea level in meters. Impacts sunrise data."

This is, and always has been, defined incorrectly.It should be defined as altitude aboveground level, not sea level.Therefore, if the optionalobserver_elevation is not specified, and your system's general elevation contains your home's altitude abovesea level,then this integration will get thewrong elevation value, resulting in incorrect sensor values.This situation should be avoided.Therefore, if it occurs, a WARNING will be generated to bring it to your attention.

The second choice is specifying an obstruction in one or both directions (sunrise_obstruction and/orsunset_obstruction).For each used, the horizontal distance to the obstruction (distance),and the height of the top of the obstruction, relative to the observer (relative_height), must be specified.Note that the relative height can be negative (e.g., the observer is on an even taller mountain.)If only one is used, then the observer's elevation above ground level (above_ground) must also be specified (for the other direction.)

Here are some examples:

observer_elevation:5observer_elevation:sunrise_obstruction:{distance: 10000, relative_height: 2000}sunset_obstruction:{distance: 5000, relative_height: -100}observer_elevation:above_ground:0sunrise_obstruction:{distance: 10000, relative_height: 2000}

Note that this replaces theelevation option used in previous versions.

Binary Sensor Configurations

A list of one or more of the following.

elevation

'on' when sun's elevation is above threshold,'off' when at or below threshold.

KeyOptionalDescription
unique_idnoUnique identifier for entity. Must be unique within set of binary sensors for location. This allows any of the remaining options to be changed without looking like a new entity.
elevationnoElevation threshold (in degrees) orhorizon
nameyesEntity friendly name

For example, this:

-unique_id:bs1elevation:horizon

Would be equivalent to:

-unique_id:bs1elevation:-0.833name:Above horizon

Sensor Configurations

A list of one or more of the following.

Time at Elevation Sensor

KeyOptionalDescription
unique_idnoUnique identifier for entity. Must be unique within set of sensors for location. This allows any of the remaining options to be changed without looking like a new entity.
time_at_elevationnoElevation (in degrees)
directionyesrising (default) orsetting
iconyesDefault ismdi:weather-sunny
nameyesEntity friendly name

For example, this:

-unique_id:s1time_at_elevation:-0.833

Would be equivalent to:

-unique_id:s1time_at_elevation:-0.833direction:risingicon:mdi:weather-sunnyname:Rising at minus 0.833 °

Elevation at Time Sensor

KeyOptionalDescription
unique_idnoUnique identifier for entity. Must be unique within set of sensors for location. This allows any of the remaining options to be changed without looking like a new entity.
elevation_at_timenoTime string orinput_datetime entity ID
nameyesEntity friendly name

When using aninput_datetime entity it must have the time component. The date component is optional.If the date is not present, the result will be the sun's elevation at the given time on the current date.If the date is present, it will be used and the result will be the sun's elevation at the given time on the given date.Also in this case, thesensor entity will not haveyesterday,today andtomorrow attributes.

Aditional Sensors

Besides the sensors described above, the following will also be created automatically. Simply enable or disable these entities as desired.

Point in Time Sensors

Some of these will be enabled by default. The rest will be disabled by default.

TypeEnabledDescription
Solar MidnightyesThe time when the sun is at its lowest point closest to 00:00:00 of the specified date; i.e. it may be a time that is on the previous day.
Astronomical DawnnoThe time in the morning when the sun is 18 degrees below the horizon
Nautical DawnnoThe time in the morning when the sun is 12 degrees below the horizon
DawnyesThe time in the morning when the sun is 6 degrees below the horizon
RisingyesAKA Sunrise. The time in the morning when the sun is 0.833 degrees below the horizon. This is to account for refraction.
Solar NoonyesThe time when the sun is at its highest point
SettingyesAKA Sunset. The time in the evening when the sun is 0.833 degrees below the horizon. This is to account for refraction.
DuskyesThe time in the evening when the sun is a 6 degrees below the horizon
Nautical DusknoThe time in the evening when the sun is a 12 degrees below the horizon
Astronomical DusknoThe time in the evening when the sun is a 18 degrees below the horizon

Length of Time Sensors (in hours)

These are all disabled by default.

TypeDescription
DaylightThe amount of time between sunrise and sunset
Civil DaylightThe amount of time between dawn and dusk
Nautical DaylightThe amount of time between nautical dawn and nautical dusk
Astronomical DaylightThe amount of time between astronomical dawn and astronomical dusk
NightThe amount of time between sunset and sunrise of the next day
Civil NightThe amount of time between dusk and dawn of the next day
Nautical NightThe amount of time between nautical dusk and nautical dawn of the next day
Astronomical NightThe amount of time between astronomical dusk and astronomical dawn of the next day

Other Sensors

These are also all disabled by default.

TypeDescription
AzimuthThe sun's azimuth (degrees)
Rising AzimuthThe sun's azimuth at sunrise (degrees)
Setting AzimuthThe sun's azimuth at sunset (degrees)
ElevationThe sun's elevation (degrees)
Minimum ElevationThe sun's elevation at solar midnight (degrees)
maximum ElevationThe sun's elevation at solar noon (degrees)
deCONZ DaylightEmulation ofdeCONZ Daylight Sensor
PhaseSeeSun Phase Sensor
Sun Phase Sensor
Possible states
StateDescription
NightSun is below -18°
Astronomical TwilightSun is between -18° and -12°
Nautical TwilightSun is between -12° and -6°
Civil TwilightSun is between -6° and -0.833°
DaySun is above -0.833°
Attributes
AttributeDescription
risingTrue if sun is rising
blue_hourTrue if sun is between -6° and -4°
golden_hourTrue if sun is between -4° and 6°

Example Full Configuration

sun2:  -unique_id:homebinary_sensors:      -unique_id:bs1elevation:horizon      -unique_id:bs2elevation:3      -unique_id:bs3elevation:-6name:Above Civil Dawnsensors:      -unique_id:s1time_at_elevation:10      -unique_id:s2time_at_elevation:-10direction:settingicon:mdi:weather-sunset-downname:Setting past 10 deg below horizon      -unique_id:s3elevation_at_time:'12:00'name:Elv @ noon      -unique_id:s4elevation_at_time:input_datetime.testname:Elv @ test var  -unique_id:londonlocation:Londonlatitude:51.50739529645933longitude:-0.12767666584664272time_zone:Europe/Londonelevation:0binary_sensors:      -unique_id:bs1elevation      -unique_id:bs2elevation:3      -unique_id:bs3elevation:-6name:Above Civil Dawnsensors:      -unique_id:s1time_at_elevation:10      -unique_id:s2time_at_elevation:-10direction:settingicon:mdi:weather-sunset-downname:Setting past 10 deg below horizon      -unique_id:s3elevation_at_time:'12:00'name:Elv @ noon      -unique_id:s4elevation_at_time:input_datetime.testname:Elv @ test var

All "simple" sensor options (e.g.,dawn,daylight, etc.) will be created automatically.Some will be enabled by default, but most will not.Simply go to the Settings -> Devices & services page, click on Sun2, then entities, and enable/disable the entities as desired.


[8]ページ先頭

©2009-2025 Movatter.jp