{
    "pluginAlias": "GrumpTechHomebridgeTimeTrigger",
    "pluginType": "platform",
    "singular": true,
    "headerDisplay": "This plugin is provided by [GrumpTech](https://github.com/pricemi115/)",
    "footerDisplay": "Be kind.....to everyone",
    "schema": {
        "type": "object",
        "properties": {
            "name": {
                "title": "Plugin Name",
                "type": "string",
                "default": "GrumpTech Homebridge Time Trigger",
                "condition": {
                    "functionBody": "return false;"
                }
            },
            "settings": {
                "title": "Settings",
                "type": "object",
                "properties": {
                    "triggers": {
                        "title": "Time Triggers",
                        "description": "List of time-based triggers.",
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "trigger_identifier": {
                                    "title": "Identifier",
                                    "description": "Unique identifier for the trigger.</br><small>Controls the mapping of the Homekit accessory to this trigger.</br>and serves as the default name for the accessory and services.</br><i><u>Note</u>: Subsequent triggers with this name will be ignored.</br><u>Warning</u>: Changing the identifier will affect existing Homekit automations using this trigger.</i></small>",
                                    "type": "string",
                                    "minLength": 1,
                                    "default": "Trigger",
                                    "pattern": "(?!^$)([^\\s])",
                                    "required": true
                                },
                                "trigger_type": {
                                    "title": "Trigger Type",
                                    "description": "Type of trigger",
                                    "type": "number",
                                    "default": 0,
                                    "oneOf": [
                                        { "title": "Timed", "enum": [0] },
                                        { "title": "Scheduled", "enum": [1] }
                                      ],
                                    "required": true
                                },
                                "timeout": {
                                    "title": "Timeout Window",
                                    "description": "Trigger timeout window",
                                    "type": "object",
                                    "required": true,
                                    "properties": {
                                        "nominal": {
                                            "title": "Trip Interval",
                                            "description": "Nominal trip interval, in milliseconds.",
                                            "type": "number",
                                            "default": 60000,
                                            "minimum": 1,
                                            "required": true
                                        },
                                        "tolerance": {
                                            "title": "Trip Interval Tolerance",
                                            "description": "Tolerance, in milliseconds, for the trip interval.</br><small>Used to randomize the trip event around the specified interval.</small>",
                                            "type": "number",
                                            "default": 0,
                                            "minimum":  0,
                                            "required": true
                                        }
                                    },
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 0));"
                                    }
                                },
                                "days": {
                                    "title": "Days",
                                    "description": "Days to trip the trigger",
                                    "type": "number",
                                    "default": 127,
                                    "minimum": 1,
                                    "oneOf": [
                                        { "title": "Sunday", "enum": [1] },
                                        { "title": "Monday", "enum": [2] },
                                        { "title": "Tuesday", "enum": [4] },
                                        { "title": "Wednesday", "enum": [8] },
                                        { "title": "Thursday", "enum": [16] },
                                        { "title": "Friday", "enum": [32] },
                                        { "title": "Saturday", "enum": [64] },
                                        { "title": "Weekdays", "enum": [62] },
                                        { "title": "Weekends", "enum": [65] },
                                        { "title": "Every day", "enum": [127] }
                                    ],
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1));"
                                    },
                                    "required": true
                                },
                                "is_astronomical": {
                                    "title": "Astronomical Trigger",
                                    "description": "Trigger trip time is based on astronomical events",
                                    "type": "boolean",
                                    "default": false,
                                    "required": true,
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1));"
                                    }
                                },
                                "astronomical_type": {
                                    "title": "Astronomical Type",
                                    "description": "Type of astronomical trigger",
                                    "type": "string",
                                    "default": "sunset",
                                    "oneOf": [
                                        { "title": "Moon Rise", "enum": ["moon_rise"] },
                                        { "title": "Moon Set", "enum": ["moon_set"] },
                                        { "title": "Sunrise", "enum": ["sunrise"] },
                                        { "title": "Sunset", "enum": ["sunset"] },
                                        { "title": "Twilight End", "enum": ["twilight_end"] },
                                        { "title": "Twilight Start", "enum": ["twilight_start"] },
                                        { "title": "Lunar Transit", "enum": ["lunar_transit"] },
                                        { "title": "Solar Transit", "enum": ["solar_transit"] }
                                    ],
                                    "required": true,
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1) && (model.settings.triggers[arrayIndices].is_astronomical === true));"
                                    }
                                },
                                "location": {
                                    "title": "Location",
                                    "description": "Location reference for the astronomical trigger",
                                    "type": "object",
                                    "properties": {
                                        "latitude": {
                                            "title": "Latitude",
                                            "description": "Latitude, expressed in 'north-positive' format",
                                            "type": "number",
                                            "minimum": -90,
                                            "maximum": 90,
                                            "default": 0,
                                            "required": true
                                        },
                                        "longitude": {
                                            "title": "Longitude",
                                            "description": "Longitude, expressed in 'east-positive' format",
                                            "type": "number",
                                            "minimum": -180,
                                            "maximum": 180,
                                            "default": 0,
                                            "required": true
                                        }
                                    },
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1) && (model.settings.triggers[arrayIndices].is_astronomical === true));"
                                    }
                                },
                                "time" : {
                                    "title": "Time settings",
                                    "description": "Time settings for scheduled triggers.",
                                    "type": "object",
                                    "properties": {
                                        "astronomical_offset": {
                                            "title": "Time Offset",
                                            "description": "Offset time for astronomical triggers",
                                            "type": "object",
                                            "properties": {
                                                "type": {
                                                    "title": "Offset Type",
                                                    "description": "Type of offset",
                                                    "type": "string",
                                                    "default": "none",
                                                    "oneOf": [
                                                        { "title": "After", "enum": ["after"] },
                                                        { "title": "Before", "enum": ["before"] },
                                                        { "title": "None", "enum": ["none"] }
                                                    ],
                                                    "required": true
                                                },
                                                "hour": {
                                                    "title": "Hour",
                                                    "description": "Hour(s) to offset from the astrological time. (00-05)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 5,
                                                    "default": 0,
                                                    "required": true,
                                                    "condition": {
                                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].time.astronomical_offset.type !== \"none\"));"
                                                    }
                                                },
                                                "minute": {
                                                    "title": "Minute",
                                                    "description": "Minute(s) to offset from the astrological time. (00-59)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 59,
                                                    "default": 0,
                                                    "required": true,
                                                    "condition": {
                                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].time.astronomical_offset.type !== \"none\"));"
                                                    }
                                                }
                                            },
                                            "condition": {
                                                "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1) && (model.settings.triggers[arrayIndices].is_astronomical === true));"
                                            }
                                        },
                                        "nominal": {
                                            "title": "Trip Time",
                                            "description": "Nominal time of day to trip the trigger. (Default time if this is an astronomical trigger)",
                                            "type": "object",
                                            "properties": {
                                                "hour": {
                                                    "title": "Hour",
                                                    "description": "Hour to trip the trigger. (00-23)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 23,
                                                    "default": 12,
                                                    "required": true
                                                },
                                                "minute": {
                                                    "title": "Minute",
                                                    "description": "Minute to trip the trigger. (00-59)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 59,
                                                    "default": 0,
                                                    "required": true
                                                }
                                            },
                                            "condition": {
                                                "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1));"
                                            }
                                        },
                                        "tolerance": {
                                            "title": "Trip Tolerance",
                                            "description": "Tolerance around the trip time.</br><small>Used to randomize the trip event around the specified trip time.</small>",
                                            "type": "object",
                                            "properties": {
                                                "hour": {
                                                    "title": "Hour",
                                                    "description": "Hour tolerance around the nominal trip time. (00-23)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 23,
                                                    "default": 0,
                                                    "required": true
                                                },
                                                "minute": {
                                                    "title": "Minute",
                                                    "description": "Minute tolerance around the trip time. (00-59)",
                                                    "type": "number",
                                                    "minimum": 0,
                                                    "maximum": 59,
                                                    "default": 0,
                                                    "required": true
                                                }
                                            }
                                        }
                                    },
                                    "condition": {
                                        "functionBody": "return (model.settings.triggers[arrayIndices] && (model.settings.triggers[arrayIndices].trigger_type === 1));"
                                    }
                                },
                                "duration": {
                                    "title": "Duration Window",
                                    "description": "Trigger trip duration window",
                                    "type": "object",
                                    "required": true,
                                    "properties": {
                                        "nominal": {
                                            "title": "Trip Duration",
                                            "description": "Nominal trip duration, in milliseconds.",
                                            "type": "number",
                                            "default": 250,
                                            "minimum": 10,
                                            "required": true
                                        },
                                        "tolerance": {
                                            "title": "Trip Duration Tolerance",
                                            "description": "Tolerance, in milliseconds, for the trip duration.</br><small>Used to randomize the trip event around the specified interval.</small>",
                                            "type": "number",
                                            "default": 0,
                                            "minimum": 0,
                                            "required": true
                                        }
                                    }
                                },
                                "trip_limit": {
                                    "title": "Trip Limit",
                                    "description": "Limit the number of times the trigger will trip. (0=Do not limit)",
                                    "type": "number",
                                    "minimum": 0,
                                    "default": 0,
                                    "required": true
                                }
                            }
                        },
                        "required": true
                    }
                }
            }
        }
    },
    "form": null,
    "display": null
}