{
  "$schema": "./.schemas/page.schema.json",
  "title": "{param.name}",
  "icon": "cloud.sun",
  "params": {
    "lat": {
      "pattern": "-?[0-9]{1,3}(\\.[0-9]{1,6})?",
      "example": "33.44",
      "default": "33.44"
    },
    "lon": {
      "pattern": "-?[0-9]{1,3}(\\.[0-9]{1,6})?",
      "example": "-94.04",
      "default": "-94.04"
    },
    "name": {
      "type": "text",
      "example": "Weather",
      "default": "Weather"
    }
  },
  "sources": {
    "weather": {
      "url": "https://api.open-meteo.com",
      "every": "15m",
      "requests": {
        "fc": "/v1/forecast?latitude={param.lat}&longitude={param.lon}&current=temperature_2m,apparent_temperature,relative_humidity_2m,dew_point_2m,weather_code,is_day,wind_speed_10m,wind_direction_10m,wind_gusts_10m,pressure_msl,visibility,uv_index&minutely_15=precipitation&forecast_minutely_15=8&hourly=temperature_2m,uv_index&forecast_hours=24&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset,rain_sum,snowfall_sum,precipitation_probability_max,wind_speed_10m_max,wind_gusts_10m_max,wind_direction_10m_dominant&forecast_days=8&temperature_unit=fahrenheit&wind_speed_unit=mph&precipitation_unit=inch&timezone=auto&timeformat=unixtime",
        "air": "https://air-quality-api.open-meteo.com/v1/air-quality?latitude={param.lat}&longitude={param.lon}&current=us_aqi,grass_pollen,birch_pollen,alder_pollen,ragweed_pollen,mugwort_pollen,olive_pollen&hourly=us_aqi&forecast_days=4&timezone=auto&timeformat=unixtime"
      },
      "derive": [
        {
          "name": "sky",
          "value": {
            "path": "fc.current.weather_code",
            "values": {
              "0": "Clear sky",
              "1": "Mainly clear",
              "2": "Partly cloudy",
              "3": "Overcast",
              "45": "Fog",
              "48": "Freezing fog",
              "51": "Light drizzle",
              "53": "Drizzle",
              "55": "Heavy drizzle",
              "56": "Freezing drizzle",
              "57": "Freezing drizzle",
              "61": "Light rain",
              "63": "Rain",
              "65": "Heavy rain",
              "66": "Freezing rain",
              "67": "Freezing rain",
              "71": "Light snow",
              "73": "Snow",
              "75": "Heavy snow",
              "77": "Snow grains",
              "80": "Rain showers",
              "81": "Rain showers",
              "82": "Heavy showers",
              "85": "Snow showers",
              "86": "Snow showers",
              "95": "Thunderstorm",
              "96": "Thunderstorm with hail",
              "99": "Thunderstorm with hail"
            },
            "default": ""
          }
        },
        {
          "name": "wet_slots",
          "value": {
            "count": "fc.minutely_15",
            "zip": true,
            "where": {
              "path": "precipitation",
              "gt": 0
            },
            "default": 0
          }
        },
        {
          "name": "rain",
          "value": {
            "each": "fc.minutely_15",
            "zip": true,
            "value": "precipitation"
          }
        },
        {
          "name": "rain_starts",
          "value": {
            "first": "time",
            "of": "fc.minutely_15",
            "zip": true,
            "where": {
              "path": "precipitation",
              "gt": 0
            }
          }
        },
        {
          "name": "rain_stops",
          "value": {
            "first": "time",
            "of": "fc.minutely_15",
            "zip": true,
            "where": {
              "path": "precipitation",
              "equals": 0
            }
          }
        },
        {
          "name": "uv_peak",
          "value": {
            "each": "fc.hourly",
            "zip": true,
            "limit": 1,
            "where": {
              "path": "time",
              "lte": {
                "answer": "fc.daily.sunset[0]"
              }
            },
            "sort": {
              "by": "uv_index",
              "order": "desc"
            },
            "fields": {
              "time": "time",
              "uvi": {
                "path": "uv_index",
                "round": 0
              }
            }
          }
        },
        {
          "name": "pressure_inhg",
          "value": {
            "path": "fc.current.pressure_msl",
            "scale": 0.02953,
            "round": 2
          }
        },
        {
          "name": "visibility_mi",
          "value": {
            "path": "fc.current.visibility",
            "scale": 0.0001893939393939394,
            "round": 0
          }
        },
        {
          "name": "pollen",
          "value": {
            "each": "air.current",
            "entries": true,
            "where": {
              "all": [
                {
                  "path": "key",
                  "in": [
                    "grass_pollen",
                    "birch_pollen",
                    "alder_pollen",
                    "ragweed_pollen",
                    "mugwort_pollen",
                    "olive_pollen"
                  ]
                },
                {
                  "path": "value",
                  "gt": 0
                }
              ]
            },
            "sort": {
              "by": "value",
              "order": "desc"
            },
            "fields": {
              "key": {
                "path": "key",
                "values": {
                  "grass_pollen": "Grass",
                  "birch_pollen": "Birch",
                  "alder_pollen": "Alder",
                  "ragweed_pollen": "Ragweed",
                  "mugwort_pollen": "Mugwort",
                  "olive_pollen": "Olive"
                }
              },
              "grains": {
                "path": "value",
                "round": 0
              }
            }
          }
        },
        {
          "name": "pollen_count",
          "value": {
            "count": "pollen",
            "default": 0
          }
        },
        {
          "name": "n_gusts",
          "value": {
            "each": "fc.daily",
            "zip": true,
            "where": {
              "all": [
                {
                  "path": "time",
                  "gt": {
                    "answer": "fc.daily.time[0]"
                  }
                },
                {
                  "path": "wind_gusts_10m_max",
                  "gte": 46
                }
              ]
            },
            "limit": 1,
            "fields": {
              "time": "time",
              "text": {
                "template": "Gusts to {wind_gusts_10m_max|round} mph {time|weekday}"
              },
              "icon": {
                "template": "wind"
              }
            }
          }
        },
        {
          "name": "n_air_0",
          "value": {
            "each": "air.hourly",
            "zip": true,
            "where": {
              "all": [
                {
                  "path": "time",
                  "gte": {
                    "answer": "fc.daily.sunrise[1]"
                  }
                },
                {
                  "path": "us_aqi",
                  "gte": 101
                }
              ]
            },
            "limit": 1,
            "fields": {
              "time": "time",
              "words": {
                "if": {
                  "path": "us_aqi",
                  "lt": 151
                },
                "then": {
                  "template": "Air unhealthy for sensitive groups"
                },
                "else": {
                  "template": "Unhealthy air"
                }
              }
            },
            "sort": {
              "by": "us_aqi",
              "order": "desc"
            }
          }
        },
        {
          "name": "n_air",
          "value": {
            "each": "n_air_0",
            "fields": {
              "time": "time",
              "text": {
                "template": "{words} {time|weekday}"
              },
              "icon": {
                "template": "lungs"
              }
            }
          }
        },
        {
          "name": "n_freeze",
          "value": {
            "each": "fc.daily",
            "zip": true,
            "where": {
              "all": [
                {
                  "path": "time",
                  "gt": {
                    "answer": "fc.daily.time[0]"
                  }
                },
                {
                  "path": "temperature_2m_min",
                  "lte": 32
                }
              ]
            },
            "limit": 1,
            "fields": {
              "time": "time",
              "text": {
                "template": "Freezing {time|weekday} night, {temperature_2m_min|round}°"
              },
              "icon": {
                "template": "snowflake"
              }
            }
          }
        },
        {
          "name": "n_rain",
          "value": {
            "each": "fc.daily",
            "zip": true,
            "where": {
              "all": [
                {
                  "path": "time",
                  "gt": {
                    "answer": "fc.daily.time[0]"
                  }
                },
                {
                  "path": "rain_sum",
                  "gte": 1
                }
              ]
            },
            "limit": 1,
            "fields": {
              "time": "time",
              "text": {
                "template": "{rain_sum|round:1} in of rain {time|weekday}"
              },
              "icon": {
                "template": "cloud.rain"
              }
            }
          }
        },
        {
          "name": "n_snow",
          "value": {
            "each": "fc.daily",
            "zip": true,
            "where": {
              "all": [
                {
                  "path": "time",
                  "gt": {
                    "answer": "fc.daily.time[0]"
                  }
                },
                {
                  "path": "snowfall_sum",
                  "gte": 1
                }
              ]
            },
            "limit": 1,
            "fields": {
              "time": "time",
              "text": {
                "template": "{snowfall_sum|round:1} in of snow {time|weekday}"
              },
              "icon": {
                "template": "snowflake"
              }
            }
          }
        },
        {
          "name": "n_some",
          "value": {
            "each": [
              "n_gusts",
              "n_air",
              "n_freeze",
              "n_rain"
            ],
            "fields": {
              "time": "time",
              "text": "text",
              "icon": "icon"
            }
          }
        },
        {
          "name": "notables",
          "value": {
            "each": [
              "n_some",
              "n_snow"
            ],
            "sort": {
              "by": "time"
            },
            "fields": {
              "text": "text",
              "icon": "icon"
            }
          }
        },
        {
          "name": "notable_count",
          "value": {
            "count": "notables",
            "default": 0
          }
        }
      ]
    },
    "alerts": {
      "url": "https://api.weather.gov",
      "every": "5m",
      "requests": {
        "nws": "/alerts/active?point={param.lat},{param.lon}"
      },
      "derive": [
        {
          "name": "alert_count",
          "value": {
            "count": "nws.features",
            "default": 0
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "alerts",
      "type": "status",
      "label": "Weather alerts",
      "state": "unknown",
      "width": "full",
      "source": {
        "ref": "alerts",
        "when": {
          "path": "alert_count",
          "gt": 0
        },
        "map": {
          "label": {
            "template": "{nws.features[0].properties.event}"
          },
          "state": {
            "path": "alert_count",
            "values": {
              "0": "ok"
            },
            "default": "warning"
          },
          "detail": {
            "if": {
              "path": "nws.features[0].properties.ends",
              "exists": true
            },
            "then": {
              "template": "Until {nws.features[0].properties.ends|day} {nws.features[0].properties.ends|clock} · {nws.features[0].properties.senderName}"
            },
            "else": {
              "template": "Until {nws.features[0].properties.expires|day} {nws.features[0].properties.expires|clock} · {nws.features[0].properties.senderName}"
            }
          }
        }
      }
    },
    {
      "id": "alert-list",
      "type": "list",
      "label": "All alerts",
      "items": [
        "—"
      ],
      "source": {
        "ref": "alerts",
        "when": {
          "path": "alert_count",
          "gt": 1
        },
        "map": {
          "items": {
            "each": "nws.features",
            "limit": 4,
            "fields": {
              "text": "properties.event",
              "detail": {
                "template": "{properties.onset|weekday} {properties.onset|clock} · {properties.severity}"
              }
            }
          }
        }
      }
    },
    {
      "id": "now",
      "type": "stat",
      "label": "Now",
      "value": 0,
      "unit": "°F",
      "url": "https://open-meteo.com",
      "source": {
        "ref": "weather",
        "map": {
          "value": {
            "path": "fc.current.temperature_2m",
            "round": 0
          },
          "delta": {
            "template": "Feels like {fc.current.apparent_temperature|round}° · {sky}"
          }
        }
      }
    },
    {
      "id": "today",
      "type": "stat",
      "label": "Today",
      "value": "—",
      "source": {
        "ref": "weather",
        "map": {
          "value": {
            "template": "{fc.daily.temperature_2m_max[0]|round}° / {fc.daily.temperature_2m_min[0]|round}°"
          },
          "delta": {
            "template": "{fc.daily.precipitation_probability_max[0]}% chance of rain"
          }
        }
      }
    },
    {
      "id": "rain",
      "type": "columns",
      "label": "Next 2 hours",
      "unit": "in",
      "series": [
        "Rain"
      ],
      "baseline": "zero",
      "items": [
        {
          "label": "Now",
          "values": [
            0
          ]
        },
        {
          "label": "15m",
          "values": [
            0
          ]
        },
        {
          "label": "30m",
          "values": [
            0
          ]
        },
        {
          "label": "45m",
          "values": [
            0
          ]
        },
        {
          "label": "1h",
          "values": [
            0
          ]
        },
        {
          "label": "1h 15",
          "values": [
            0
          ]
        },
        {
          "label": "1h 30",
          "values": [
            0
          ]
        },
        {
          "label": "1h 45",
          "values": [
            0
          ]
        }
      ],
      "source": {
        "ref": "weather",
        "when": {
          "path": "wet_slots",
          "gt": 0
        },
        "map": {
          "label": {
            "if": {
              "path": "fc.minutely_15.precipitation[0]",
              "gt": 0
            },
            "then": {
              "if": {
                "path": "rain_stops",
                "exists": true
              },
              "then": {
                "template": "Rain stopping {rain_stops|in}"
              },
              "else": {
                "template": "Rain for the next 2 hours"
              }
            },
            "else": {
              "template": "Rain starting {rain_starts|in}"
            }
          },
          "items[0].values[0]": {
            "path": "rain[0]",
            "round": 2
          },
          "items[1].values[0]": {
            "path": "rain[1]",
            "round": 2
          },
          "items[2].values[0]": {
            "path": "rain[2]",
            "round": 2
          },
          "items[3].values[0]": {
            "path": "rain[3]",
            "round": 2
          },
          "items[4].values[0]": {
            "path": "rain[4]",
            "round": 2
          },
          "items[5].values[0]": {
            "path": "rain[5]",
            "round": 2
          },
          "items[6].values[0]": {
            "path": "rain[6]",
            "round": 2
          },
          "items[7].values[0]": {
            "path": "rain[7]",
            "round": 2
          }
        }
      }
    },
    {
      "id": "hours",
      "type": "columns",
      "label": "Next 24 hours",
      "unit": "°F",
      "series": [
        "Temperature"
      ],
      "baseline": "auto",
      "values_on_top": true,
      "items": [],
      "source": {
        "ref": "weather",
        "map": {
          "highlight": {
            "template": "{fc.hourly.time[0]|hour}"
          },
          "items": {
            "each": "fc.hourly",
            "zip": true,
            "limit": 24,
            "buckets": 12,
            "keep": {
              "min": "time"
            },
            "fields": {
              "label": {
                "template": "{time|hour}"
              },
              "values[0]": {
                "path": "temperature_2m",
                "round": 0
              }
            }
          }
        }
      }
    },
    {
      "id": "conditions",
      "type": "facts",
      "label": "Conditions",
      "items": [
        {
          "key": "Air quality",
          "value": "—"
        },
        {
          "key": "UV index",
          "value": "—"
        },
        {
          "key": "Wind",
          "value": "—"
        },
        {
          "key": "Humidity",
          "value": "—"
        },
        {
          "key": "Pressure",
          "value": "—"
        },
        {
          "key": "Visibility",
          "value": "—"
        }
      ],
      "source": {
        "ref": "weather",
        "map": {
          "items[0].value": {
            "if": {
              "path": "air.current.us_aqi",
              "lt": 51
            },
            "then": {
              "template": "Good"
            },
            "else": {
              "if": {
                "path": "air.current.us_aqi",
                "lt": 101
              },
              "then": {
                "template": "Moderate"
              },
              "else": {
                "if": {
                  "path": "air.current.us_aqi",
                  "lt": 151
                },
                "then": {
                  "template": "Unhealthy for sensitive groups"
                },
                "else": {
                  "if": {
                    "path": "air.current.us_aqi",
                    "lt": 201
                  },
                  "then": {
                    "template": "Unhealthy"
                  },
                  "else": {
                    "if": {
                      "path": "air.current.us_aqi",
                      "lt": 301
                    },
                    "then": {
                      "template": "Very unhealthy"
                    },
                    "else": {
                      "template": "Hazardous"
                    }
                  }
                }
              }
            }
          },
          "items[1].value": {
            "if": {
              "path": "uv_peak[0].time",
              "exists": true
            },
            "then": {
              "template": "{fc.current.uv_index|round} now · {uv_peak[0].uvi} at {uv_peak[0].time|clock_hour}"
            },
            "else": {
              "template": "{fc.current.uv_index|round} now"
            }
          },
          "items[2].value": {
            "template": "{fc.current.wind_speed_10m|round} mph {fc.current.wind_direction_10m|compass} · gusts {fc.current.wind_gusts_10m|round}"
          },
          "items[3].value": {
            "template": "{fc.current.relative_humidity_2m}% · dew point {fc.current.dew_point_2m|round}°"
          },
          "items[4].value": {
            "template": "{pressure_inhg} inHg"
          },
          "items[5].value": {
            "template": "{visibility_mi} mi"
          }
        }
      }
    },
    {
      "id": "pollen",
      "type": "facts",
      "label": "Pollen",
      "items": [],
      "source": {
        "ref": "weather",
        "when": {
          "path": "pollen_count",
          "gt": 0
        },
        "map": {
          "items": {
            "each": "pollen",
            "fields": {
              "key": "key",
              "value": {
                "template": "{grains} grains/m³"
              }
            }
          }
        }
      }
    },
    {
      "id": "daylight",
      "type": "window",
      "label": "Daylight left",
      "start": "2026-01-01T12:00:00Z",
      "end": "2026-01-01T23:00:00Z",
      "start_label": "Sunrise",
      "end_label": "Sunset",
      "before_label": "Until sunrise",
      "after_label": "Until sunrise",
      "source": {
        "ref": "weather",
        "map": {
          "start": "fc.daily.sunrise[0]",
          "end": "fc.daily.sunset[0]",
          "next_start": "fc.daily.sunrise[1]"
        }
      }
    },
    {
      "id": "week",
      "type": "ranges",
      "label": "This week",
      "unit": "°F",
      "colors": "temperature",
      "info_colors": [
        "green",
        "blue"
      ],
      "muted": false,
      "items": [
        {
          "label": "Today",
          "low": 0,
          "high": 1
        }
      ],
      "source": {
        "ref": "weather",
        "map": {
          "items": {
            "each": "fc.daily",
            "zip": true,
            "limit": 8,
            "fields": {
              "label": {
                "template": "{time|weekday}"
              },
              "low": {
                "path": "temperature_2m_min",
                "round": 0
              },
              "high": {
                "path": "temperature_2m_max",
                "round": 0
              },
              "icon": {
                "path": "weather_code",
                "values": {
                  "0": "sun.max",
                  "1": "sun.max",
                  "2": "cloud.sun",
                  "3": "cloud",
                  "45": "cloud.fog",
                  "48": "cloud.fog",
                  "51": "cloud.drizzle",
                  "53": "cloud.drizzle",
                  "55": "cloud.drizzle",
                  "56": "cloud.sleet",
                  "57": "cloud.sleet",
                  "61": "cloud.rain",
                  "63": "cloud.rain",
                  "65": "cloud.heavyrain",
                  "66": "cloud.sleet",
                  "67": "cloud.sleet",
                  "71": "cloud.snow",
                  "73": "cloud.snow",
                  "75": "cloud.snow",
                  "77": "cloud.snow",
                  "80": "cloud.sun.rain",
                  "81": "cloud.rain",
                  "82": "cloud.heavyrain",
                  "85": "cloud.snow",
                  "86": "cloud.snow",
                  "95": "cloud.bolt",
                  "96": "cloud.bolt.rain",
                  "99": "cloud.bolt.rain"
                },
                "default": "cloud"
              },
              "info[0]": {
                "template": "{wind_speed_10m_max|round} {wind_direction_10m_dominant|compass}"
              },
              "info[1]": {
                "if": {
                  "path": "precipitation_probability_max",
                  "gte": 10
                },
                "then": {
                  "template": "{precipitation_probability_max}%"
                },
                "else": {
                  "template": ""
                }
              }
            }
          },
          "items[0].now": {
            "path": "fc.current.temperature_2m",
            "round": 0
          }
        }
      }
    },
    {
      "id": "notable",
      "type": "list",
      "layout": "chips",
      "max_items": 3,
      "items": [],
      "source": {
        "ref": "weather",
        "when": {
          "path": "notable_count",
          "gt": 0
        },
        "map": {
          "items": {
            "each": "notables",
            "fields": {
              "text": "text",
              "icon": "icon"
            }
          }
        }
      }
    }
  ]
}
