Sun

The sun extension works with the Sunrise Sunset API to provide data about sunset and sunrise times. This is really useful to adjust watering times and fire automations based on the sun position.

This extension does not take an extension level config and is focused on interfaces.


Sun Sensor

To gather data about the sun you need to add a sensor using the sun interface. The sensors uses a location in the form of latitude and longitude. If you do not provide the location then MudPi will default to the ones set in the main mudpi config. Most map tools will provide these values for you if you search an address.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
name[String]NoA friendly display name useful for UI.
latitude[Float]NoA float containing the latitude coordinate.
longitude[Float]NoA float containing the longitude coordinate.

Here is an example of a complete sun config:

"sensor": [{
    "key": "sun",
    "interface": "sun",
    "name": "Sun",
    "latitude":40.1,
    "longitude": -20.3
}]

Sun Data

The state available from the sun sensor contains a dict with the following keys:

{
"sunrise": '2030-05-19 00:00:00 AM',
"sunset": '2030-05-19 00:00:00 AM',
"solar_noon": '2030-05-19 00:00:00 AM',
"day_length": '00:00:00',
"past_sunrise": False,
"past_sunset": False
}

Note: Data is only requested every 4 hours to be respectful the API requirements and because the sun data only changes once a day.


Trigger Interface

The sun extension also provides a trigger that compares sun times against set datetime thresholds. For most situations you should use a state trigger to check sun times or the helper values past_sunset and past_sunrise. However is some cases you may want to fire events exactly at sunrise and sunset. This is where the sun trigger is useful.

OptionTypeRequiredDescription
key[String]YesUnique slug id for the component
source[String]YesComponent key to check for new state.
nested_source[String]YesSet to the key of value the trigger should response to. Options: sunset, sunset, solar_noon. Default: None
frequency[String]NoNumber of times to trigger actions once trigger is active. Options: once, many. Default: once
name[String]NoFriendly display name of component. Useful for UI.
actions[List]NoList of registered actions to fire.
offset[Object]NoObject of offset time if you wish to check for a time before or after sun event.
offset.hours[Integer]NoNumber of hours to offset the time comparison by.
offset.minutes[Integer]NoNumber of minutes to offset the time comparison by.
offset.seconds[Integer]NoNumber of seconds to offset the time comparison by.

Config Examples

Here is a config of a trigger that fires 1 hour before sunset.

"trigger": [{
    "key": "sunset_trigger",
    "interface": "sun",
    "source": "sun_sensor_1",
    "nested_source": "sunset"
    "offset": {
        "hours":-1,
        "minutes": 0,
        "seconds":0
    }
    "name": "Trigger At Sunset",
    "actions": ["toggle.turn_on"]
}]

The configuration above would turn_on all toggles at 1 hour before sunset.