Documentation
Sun Extension
The Sun extension provides sunrise and sunset data using the Sunrise Sunset API for time-based automations.
Overview
The sun extension works with the Sunrise Sunset API to provide data about sunset and sunrise times. This is useful for adjusting watering schedules and firing automations based on the sun's position.
This extension does not require extension-level configuration and is focused on interfaces.
Sun Sensor
To gather sun data, add a sensor using the sun interface. Provide a location as latitude and longitude. If omitted, MudPi defaults to the values set in the main mudpi config.
| Option | Type | Required | Description |
|---|---|---|---|
key |
String | Yes | Unique slug identifier for the component |
name |
String | No | Friendly display name for the component |
latitude |
Float | No | Latitude coordinate for the location |
longitude |
Float | No | Longitude coordinate for the location |
{
"sensor": [
{
"key": "sun",
"interface": "sun",
"name": "Sun",
"latitude": 40.1,
"longitude": -20.3
}
]
}
Sun Data
The state returned by the sun sensor contains:
{
"sunrise": "2030-05-19 06:00:00 AM",
"sunset": "2030-05-19 08:30:00 PM",
"solar_noon": "2030-05-19 01:15:00 PM",
"day_length": "14:30:00",
"past_sunrise": false,
"past_sunset": false
}
Note
Data is only requested every 4 hours to respect the API requirements and because sun data only changes once a day.
Trigger Interface
The sun extension also provides a trigger that compares sun times against datetime thresholds. For most situations, use a state trigger to check sun times or the helper values past_sunset and past_sunrise. The sun trigger is useful when you need to fire events exactly at sunrise or sunset.
| Option | Type | Required | Description |
|---|---|---|---|
key |
String | Yes | Unique slug identifier for the component |
source |
String | Yes | Component key to check for new state |
nested_source |
String | Yes | Value to respond to: sunset, sunrise, or solar_noon |
frequency |
String | No | How many times to trigger: once or many. Default: once |
name |
String | No | Friendly display name for the component |
actions |
List | No | List of registered actions to fire |
offset |
Object | No | Time offset for checking before or after a sun event |
offset.hours |
Integer | No | Hours to offset the comparison by |
offset.minutes |
Integer | No | Minutes to offset the comparison by |
offset.seconds |
Integer | No | Seconds to offset the comparison by |
{
"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 1 hour before sunset.
Tip
Use negative offset values to trigger actions before a sun event, and positive values for after. For example, -1 hour means one hour before sunset.