Skip to content

Repository files navigation

☀️ Sun Bathing

A Home Assistant custom integration that scores hourly sunbathing conditions using Open-Meteo weather data — tuned for places where good weather is rare enough that the thresholds need to be forgiving (built with Scotland's weather in mind).

Each day is split into seven one-hour windows (10am–5pm), each scored 0–100 based on apparent temperature, cloud cover, direct solar radiation, wind speed, wind gusts, and UV index. Includes a custom Lovelace card with a tabbed 3-day forecast view, and a built-in daily notification option.

Features

  • 🌤️ 7 hourly window sensors (10am–11am through 4pm–5pm), each scored 0–100
  • 📅 3-day forecast built into every sensor's attributes
  • 🎨 Custom Lovelace card — color-coded scores, threshold-aware icons, tabbed day view — registers itself automatically, no manual setup
  • ⚙️ Editable anytime — adjust thresholds after setup via the integration's Configure option, no need to remove and re-add
  • 🎛️ Presets — Forgiving / Balanced / Strict, or fully custom — available both at initial setup and afterward
  • 🔔 Built-in daily notification — lists every window today that meets your threshold, or use the included blueprint instead if you want more control
  • 🧪 Tested — full test suite across the API client, coordinator, sensors, config flow, and options flow

Requirements

  • Home Assistant Core 2026.5.0 or later. This is a hard requirement, not just a recommendation — earlier versions have a core bug (home-assistant/core#165767) where automatically registering a Lovelace resource before the frontend has loaded its resource list can silently delete every other Lovelace resource you have. That bug is fixed in 2026.5.0+, which is why this integration won't declare compatibility with anything older.

Installation

HACS (recommended)

  1. In HACS, search for "Sun Bathing" and install
  2. Restart Home Assistant

If it doesn't show up in search, add it as a custom repository first: HACS → Integrations → ⋮ → Custom repositories → add https://github.com/dyslexicdogo/sun_bathing as an Integration, then search and install as above.

Manual

  1. Copy custom_components/sun_bathing into your Home Assistant config/custom_components/ folder
  2. Restart Home Assistant

Setup

  1. Go to Settings → Devices & Services → Add Integration
  2. Search for Sun Bathing
  3. Walk through the setup wizard:
    • Location — latitude/longitude (defaults to your Home Assistant location)
    • Preset — Forgiving, Balanced, Strict, or Custom (keeps the built-in defaults, editable on the next screens)
    • Thresholds — the "good enough" value for each weather factor
    • Ranges — how quickly each factor's score falls off as conditions move away from the threshold
    • Weights — how much each factor matters to your overall score (0–5 each; auto-normalized, so they don't need to add up to anything specific)
    • Notifications (optional) — enable a daily notification, pick a notify target, a time, and a minimum score

Once complete, you'll have 7 sensor entities: sensor.sunbathing_score_10_00_11_00 through sensor.sunbathing_score_16_00_17_00.

The Lovelace card is registered automatically — see The Lovelace Card below.

Preset comparison

Factor Forgiving Balanced Strict
Min apparent temperature 5.0 °C 12.0 °C 18.0 °C
Max cloud cover 60% 45% 25%
Min direct radiation 300 W/m² 400 W/m² 550 W/m²
Max wind speed 24.1 km/h 20.0 km/h 14.0 km/h
Max wind gust 29.0 km/h 25.0 km/h 18.0 km/h
Min UV index 5.0 4.0 5.5

Editing Settings Later

You don't need to remove and re-add sun_bathing to change anything:

  1. Settings → Devices & Services → Sun Bathing → ⚙️ Configure
  2. Pick a preset — Forgiving, Balanced, Strict, or Custom (keeps your current threshold/range/weight values, for fine-tuning). Your notification settings are never affected by this choice, regardless of which preset you pick.
  3. The next screen shows everything grouped into collapsible sections — Thresholds (expanded), Ranges, Weights, and Notifications (collapsed by default) — all pre-filled and fully editable
  4. Save — changes take effect immediately, no restart needed

The Lovelace Card

A custom card (custom:sun-bathing-card) shows all 7 windows at a glance, with tabs for Today / Tomorrow / Day+2, color-coded scores (red/amber/green), and per-factor icons that switch based on whether that factor is above or below its threshold.

The card and its Lovelace resource are registered automatically once the integration is set up — nothing to add manually. If it doesn't appear right away, restart Home Assistant once; registration is reliable on startup but can occasionally lag behind adding a brand-new config entry while HA is already running.

Add it to a dashboard: + Add Card → Manual, then:

type: custom:sun-bathing-card

Notifications

Two ways to get notified about good sunbathing windows — pick whichever suits you, or use both.

Option 1: Built-in (simplest)

Configured directly in the integration (see Editing Settings Later above, or during initial setup):

  • Enable daily notification — on/off
  • Notify service — a dropdown of detected notify targets on your system (mobile app, browser push, etc.), plus you can type any other service name
  • Notification time — defaults to 7:00 AM
  • Minimum score to notify — defaults to 50; only windows scoring at or above this are mentioned

If no window meets the threshold that day, no notification is sent at all. Otherwise you'll get one message listing every qualifying window, e.g.:

There is a sunbathing window today: 10am-11am (72), 2pm-3pm (65)

Option 2: Blueprint (more control)

If you want custom phrasing, multiple notification targets, or additional conditions, use the included blueprint instead:

  1. Settings → Automations & Scenes → Blueprints tab → Import Blueprint
  2. Paste: https://github.com/dyslexicdogo/sun_bathing/blob/main/blueprints/automation/sun_bathing/morning_notification.yaml
  3. Preview → Import Blueprint
  4. Automations tab → Create Automation → select "Sunbathing Morning Notification"
  5. Configure the 7 window sensors, your notify service, time, and minimum score
  6. Save

Both options use a notification tag/ID so each day's message replaces the previous one rather than piling up.

Roadmap

  • diagnostics.py support
  • Additional presets or a way for users to save their own named presets

Development

Built incrementally as a learning project — see sun_bathing_project_summary.md for the full architecture notes, design decisions, and phase-by-phase build log.

Tests: pytest tests/ -v

License

MIT — see LICENSE.

About

Home Assistant integration scoring hourly sunbathing conditions using Open-Meteo, tuned for Scottish weather

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages