Warning: This blog post talks about wiring things up to mains electricity which can kill you very quickly. Don't attempt anything like this unless you are competent and if in doubt ALWAYS refer to a qualified electrician.
Project Introduction
We used to have a boring, but functional, PIR-operated floodlight covering the driveway and garage. Until it broke. Well, to be fair, I broke it during my investigations into the RCD tripping caper. But either way, it needed to be replaced. And that presented an opportunity for an upgrade project.
Project scope (standard):
New lighting around the driveway
Also add lights around garage to improve illumination
Needs to look pretty but also offer useful light levels so we can see
Triggered by motion sensor
Project scope (because let's automate everything):
Integration into Home Assistant
Customisable/easily-changed courtesy light timer
Trigger optimised for sunrise/sunset
Trigger can be a combination of PIR sensor(s) and motion detect events from my CCTV cameras
Manual over-ride
Inhibit of exterior lighting operation during the festive season when the Christmas lights provide plenty of illumination by themselves
Linking of the exterior light above the front door (which is already integrated into Home Assistant using a Sonoff Mini WiFi relay) with the driveway lights
Out of scope
Using off the shelf smart lighting for this project, because it's a little too unnecessary.
Hardware shopping
Conduit
The exterior cabling will be enclosed in black plastic conduit because it is neat, and it means I don't need to get messy with chasing cabling into mortar or get angry wrangling SWA cable.
Light Fixtures
There's a fashion around here for cylindrical exterior lighting fixtures that light both up and down the building. I think these look really smart, so it was just a case of finding some that looked good but also could be mounted to conduit boxes. A quick web search later and I found some perfect ones from TLC: 'Coastal' GU10 LED, exterior rated, up and down wall lights in black.
I can fit in four of these fixtures:
Two on an exterior wall by the steps to the front door
Two to sit aside the garage door.
Motion Sensing
The primary trigger for the driveway lights is motion detection. This is usually achieved with a PIR sensor. I wanted all four fixtures to switch together so the project obviously called for a single PIR sensor switching multiple fixtures. Some light fixtures come with sensors built-in, but without buying one to look at, I wasn't sure if I could wire it up with the built-in sensor switching additional fixtures, or even if it would be rated for the additional load. It wasn't worth the gamble. And I didn't really want little PIR domes on the light fixtures themselves. Therefore an external PIR sensor was required. These are easily available, the one I found from TLC is the Luxomat 180° PIR 1kw Load 10m Detection in Black.
I also have my CCTV cameras integrated into Home Assistant so through the UniFi integration I can access the motion detection events from them. I've been using the motion detect event from my front door camera to trigger the outdoor light above the door for a while, which works well enough, but due to camera coverage of the driveway and a minor reliability issue with the UniFi controller (it sometimes goes into a sulk), I decided that camera-based motion detection should only be a secondary trigger for the driveway. A 'proper' PIR sensor for the primary trigger feels more robust to me and also makes it easy to de-automate the system with a minor wiring change in the future should I need to.
WiFi Relay
Shelly is my go-to vendor for WiFi relays. I needed a single-channel relay (dimming not required) with switch input (for the PIR), and why not add power monitoring as well? The Shelly Plus 1PM offers all of this. It's a 2nd generation device based on the ESP32 microcontroller and using a Websockets API compared to the former generation's ESP8266 with CoIoT API. It'll be my first 2nd generation Shelly, but the Shelly Home Assistant integration works with both kinds of device so this isn't even a concern.
Ancillary Notes
The exterior cabling will be enclosed in black plastic conduit, because SWA cable is too hard to work with and the additional wiring for the PIR sensor is more neatly added to a conduit rather than using a separate run of SWA to get the sensor in the correct position on the exterior of my property.
I will use 1.5mm² conduit cabling. It's slight overkill; this project is very low-current so standard 'lighting' 1.0mm² cable would be fine even when taking into account the de-rating that applies to wires inside a conduit. But TLC doesn't sell 1.0mm² conduit cable and using something a bit thicker is never a bad idea anyway, providing it fits in the terminals.
The fixtures aside the garage door will be mounted directly on the walls with new holes drilled through the bricks into the garage. Standard 1.0mm² twin and earth cabling can be used for them.
Conduit Fitting
Light Fixtures
Knowing this installation needed light fixtures mounted on conduit posed a bit of a challenge: Finding fixtures that have circular mounts, and of a size compatible with the standard round conduit fittings. I didn't want to have to T-junction the conduit down to each fitting if I could avoid it. The fixtures I selected looked about right, the dimensions suggested the circular mounting was within a couple of mm of the conduit fittings, but it was still a bit of a gamble until the delivery arrived and I could line things up and really see how it would work. And fortunately, it worked perfectly:
The rubber seal and hard lid needed a single hole drilled for the cables. The light fixture's rear mount had a pre-drilled hole for the cables but didn't have bolt holes in the right place for the conduit box, so needed two holes drilled.
PIR Sensor Cable
The PIR sensor wasn't so amicable to working with conduit. The mounting box is too small to accept a conduit directly so the only way is to use flexible cable. I therefore needed a way to get flexible cable into a conduit in a weatherproof manner. Again, this was a case of buying stuff online and hoping it fitted together. I found standard M20 cable glands screw perfectly into the sort of threaded conduit adaptors intended to attach conduit to junction boxes and the like. The gland has a rubber gromit to seal against the flex and prevent water ingress into the conduit. Very neat.
Wiring Diagram
Within the garage, the Shelly and connectors will be mounted in a plastic junction box.
I considered mounting the Shelly in the plastic conduit outside, but the WiFi signal is stronger in the garage and as I needed a junction box inside to connect the garage door lights it was the obvious place to put it. This did mean I needed to run the live and switched-live wires to the PIR out of the garage and back again.
The whole system (fixtures, conduit and Shelly junction box) is double insulated so I didn't need to run earth connections anywhere.
Installation
All I needed now was a day of good weather! Soon a Saturday presented itself.
The PIR sensor cable is stranded rubber flex. Even using ferrules to tame the strands I wasn't able to get the wires into push-fit Wago 773 series connectors. So I used Wago 222 series instead, they're a bit larger and fill up most of the room in the junction box but they work better with the wires.
Also shown here is how neat the M20 cable gland ended up looking.
The mains incomer is the top-right (white) cable. The bottom white cable and the grey cable connect to the two exterior fixtures attached to the garage walls. Finally, the four conduit wires (neutral, switched live to lights, live to PIR and switched-live from PIR) are visible.
There's a bit of crossing of colours of the cabling; the old exterior light was wired with black and red twin&earth cable but new stuff I bought for this project uses harmonised colours: brown and blue.
Configuration
Shelly
The PIR sensor's switched-live is connected to the Shelly's switch input. The switch input, by default, engages the relay. In order to intercept the PIR's trigger (so I can inhibit it at times of day, or if the Christmas lights are on) I configured the Shelly's input to act independently of the relay, this is called a detatched input in the config and means I'm using the input and output as two separate functions.
On its own, then, the PIR trigger won't turn on the lights. I am therefore reliant on the Home Assistant automation to act on the trigger, check some conditions, and turn on the lights if it's right to do so. This is a departure from my usual policy of using Home Assistant only in a supportive manner, but the benefits offered by letting the automation take full control outweight my misgivings. A simple config change on the Shelly would reconnect the switch (PIR) input directly to the relay if I need in future - or indeed a quick bit of rewiring in the junction box could be done to remove the Shelly altogether.
Bootnote: The GUI for the 2nd generation Shelly is really comprehensive. I'm impressed.
Home Assistant
The last bit of magic needed for the correct operation is the automation in Home Assistant. This acts on motion detection either from the PIR (via Shelly input) or from the front door camera. The automation then checks that the sun has set, and that the Christmas lights aren't on. If it's ok to proceed, the automation turns the driveway and front door lights on and starts a courtesy timer (using a script) to turn them off after 5 minutes.
There's no need to debounce the motion triggers because the PIR and camera already do this. In the case of the PIR I set its internal switch-on time to the shortest possible (about 10 seconds) to get the most accurate reporting of motion into Home Assistant. If I was using the PIR to drive the lights directly, obviously this would need to be set to 5 minutes. I left the PIR's lux setting on max so it ignores the light level. Again, usually this setting would be used to inhibit the PIR trigger during daytime but I figured it might be fun to get motion detection reporting into Home Assistant even during the day, and the automation's condition will then stop the lights turning on during daylight hours.
Automation YAML:
alias: "Automation: Front courtesy lights"
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.front_door_motion
to: "on"
from: "off"
- platform: state
entity_id:
- binary_sensor.shelly_driveway_switch_0_input
from: "off"
to: "on"
condition:
- condition: and
conditions:
- condition: sun
before: sunrise
after: sunset
after_offset: "00:15:00"
- condition: state
entity_id: switch.christmas_lights_master_outside
state: "off"
action:
- service: switch.turn_on
data: {}
target:
entity_id:
- switch.outside_light
- switch.shelly_driveway_switch_0
- service: script.turn_on
data: {}
target:
entity_id: script.front_door_courtesy_light
mode: single
The Finished Job
It ended up being a full day's work, but I am hugely pleased with the result.
A job well done, even if I do say so myself.
Comments