Project Debrief: UV Index on Home Assistant

Project Goals

I use Home Assistant for home automation, with a handy dashboard visible in my living room. On sunny days, I would like to know whether I need sunscreen so a UV index display is ideal. Home Assistant does already have a UV Index integration but is has two issues:

  1. It requires signing up for an account on the data provider. This is not a dealbreaker, but something I’d have liked to avoid.
  2. The existing options all show a daily maximum. Living in Seattle the UV index often drops pretty early in the day and so more granular data is desired. While researching UV index I found a neat hourly visualization that I wanted to emulate1:

Design

The first step in this project is to fetch data from a source that provides hourly UV and does not require an API key. In the United States, the EPA provides just such an API, so a fairly straightforward sensor integration can fetch that data. The daily maximum is stored as the primary sensor value to make conventional use easy, and the hourly forecast is stored in an attribute.

The code for this integration is on github at github.com/davidn/epa_uvindex.

The second step is to render the data. Now a simple gauge with some custom values and colors can produce a nice daily maximum visualization:

However the conventional Home Assistant dashboard components are insufficient for the hourly display. I therefore wrote a custom dashboard card for displaying the hourly data stored in an attribute in a manner close to my goal:

The code for the dasbhoard is on github at github.com/davidn/uvindex-hourly.

I then added the metadata to allow quick installation using HACS, and added the EPA logo to Home Assistant’s brand repository so an appropriate icon appears.

Fate

This project continues to be used in my Home Assistant installation and judging by github stars, bug submitted, and the Home Assistant community, a few other people too.

  1. World Health Organization, World Meteorological Organization, United Nations Environment Programme, and International Commission of Non-Ionizing Radiation Protection. 2002. Global Solar UV Index: A Practical Guide. WHO/SDE/OEH/02.2. Geneva: World Health Organization. https://www.who.int/publications/i/item/9241590076. ↩︎

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *