For a long time, the light on my porch was turned on based on sunset. When sunset arrived, the light would come on. While it worked okay, it was far from perfect, with the light sometimes coming on when it was still fairly bright, or not coming on despite it having gotten quite dark. Automating the light using the weather solved my problems.
Why time-based porch light automations can fail
Darkness isn’t solely determined by the time of day
There are plenty of ways to create automations in Home Assistant to turn on your porch lights. You can use a timer to get your light to turn on at the same time each evening. The problem with this method is that the light levels at 7 PM in the winter and 7 PM in the summer can be very different.
A simple solution is to create an automation based on the sunset time. You can have the light turn on at the exact time of sunset each day, and this time will vary throughout the year. Using the exact sunset time isn’t always ideal, so you can use an adjustment to make the light turn on half an hour after sunset, or 20 minutes before.
The issue is that the sun isn’t the only thing that affects how dark it is. If there’s significant cloud cover, it can be much darker than when there are clear skies. If it’s raining heavily, it will be darker than when it’s sunny.
I wanted my porch light to turn on when it was dark enough to need it. Using a time-based automation, this wasn’t always happening; there were plenty of times when it started to get dark long before the light turned on.
- Dimensions (exterior)
-
4.41″L x 4.41″W x 1.26″H
- Weight
-
12 Ounces
Home Assistant Green is a pre-built hub directly from the Home Assistant team. It’s a plug-and-play solution that comes with everything you need to set up Home Assistant in your home without needing to install the software yourself.
Estimating outdoor brightness in Home Assistant
A custom integration can estimate outdoor brightness
A time-based automation can’t respond to actual light levels; it only knows what time it is. I wanted my porch light to turn on when it was dark enough to be needed, rather than at any specific time.
That’s when I discovered a custom integration for Home Assistant called Illuminance Sensor. As the name suggests, the integration creates a sensor entity that provides an estimate of the current illuminance in your location. It uses an algorithm developed by the United States Naval Observatory that produces an estimate of solar illuminance based on the elevation of the sun.
There’s also a simple mode that uses the time of day rather than sun elevation, but since I’d already tried time-based automations, I stuck to the default mode. You can install the Illuminance Sensor integration via HACS. It’s not part of the HACS library, so you’ll need to add it as a custom repository, download it via HACS, and then restart Home Assistant. You can then install it like any other integration.
Using the basic settings of the Illuminance Sensor integration, I got an initial illuminance value of around 74,000 lx. This is a reasonable value for full daylight in the summer, so it seemed like the integration was doing its job.
5 wild smart home sensors you can integrate with Home Assistant
Great gifts for the smart home nerd in your life.
Adding weather data makes the results more accurate
Cloud cover and weather conditions can make it darker
The problem with using the default settings is that they still don’t take into account the weather conditions, which is the whole reason I set up the integration in the first place. However, in the Illuminance Sensor configuration, you can provide the entity ID of a weather integration. Using a supported weather integration, the sensor can adjust the illuminance value based on the weather conditions and cloud cover.
The integration supports weather entities from AccuWeather, Buienradar, ecobee, Met.no, and OpenWeatherMap. If you’re using OpenWeatherMap, you can also use the openweathermap_cloud_coverage and openweathermap_condition sensors instead.
Using the OpenWeatherMap weather entity, the illuminance dropped to around 38,000 lx, which seemed more realistic based on the cloud cover at the time. Using the condition sensor, it gave a similar result of around 39,000 lx, but when I switched to the cloud_coverage sensor, the value rose to 47,000 lx.
This made sense to me; if the weather entity or condition sensor says that it’s cloudy, the integration will make the same adjustment, whether there’s 30% cloud cover or 70% cloud cover. Using the cloud coverage sensor, it gets a more specific measure of cloud cover, so the adjustment may be more accurate. I ended up sticking with the cloud coverage sensor, and it’s worked well for me so far.
The final step was to create an automation to turn on the porch light when the illuminance sensor fell below a set threshold. It took a bit of tweaking, but it’s now the case that my porch light is almost always on when it’s dark enough to warrant it.
You don’t always need to buy more hardware
You could use a lux sensor to measure the light levels directly, but I found that the lux reading in my motion sensors was capped at a maximum value of 1364 lx, so it was useless for my needs. I didn’t want to have to buy another sensor just for this purpose, and using this clever integration, there was no need to do so.


