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.
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.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
name | [String] | No | A friendly display name useful for UI. |
latitude | [Float] | No | A float containing the latitude coordinate. |
longitude | [Float] | No | A 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
}]
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.
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.
Option | Type | Required | Description |
key | [String] | Yes | Unique slug id for the component |
source | [String] | Yes | Component key to check for new state. |
nested_source | [String] | Yes | Set to the key of value the trigger should response to. Options: sunset , sunset , solar_noon . Default: None |
frequency | [String] | No | Number of times to trigger actions once trigger is active. Options: once , many . Default: once |
name | [String] | No | Friendly display name of component. Useful for UI. |
actions | [List] | No | List of registered actions to fire. |
offset | [Object] | No | Object of offset time if you wish to check for a time before or after sun event. |
offset.hours | [Integer] | No | Number of hours to offset the time comparison by. |
offset.minutes | [Integer] | No | Number of minutes to offset the time comparison by. |
offset.seconds | [Integer] | No | Number of seconds to offset the time comparison by. |
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.