Controlling mains power with GPIO (In a compliant way)

Post Reply
SirHumphreyAppleby
Posts: 4
Joined: Mon Apr 13, 2020 8:34 am
Answers: 0
Has thanked: 0
Been thanked: 0

Controlling mains power with GPIO (In a compliant way)

Post by SirHumphreyAppleby »

This question was originally posted on Geekzone, but the replies have mainly focused on plug/wire-in devices, not the question of compliance I am trying to answer.

Original post:

I am bringing forward plans for automation due to a desire to add additional security sensors. My plans will require controlling mains power (lighting initially) via GPIO on a Raspberry Pi. The Pi will also be used as inputs for sensors, while providing a connection via wired Ethernet, and MQTT.

What do I need to do to connect this all together in a compliant way? Obviously the mains voltage stuff needs to be completed by a qualified person and I will consult them ahead of time so they know exactly what I'm planning.

My initial thought was to put everything on a DIN rail in the ceiling. I found this blog post showing a similar setup in Australia. I note that everything is in an enclosure and they are using 24V signalling (not GPIO) and is connected via a second set of terminals so they don't need to touch the relays if they change the input later. I'm hoping this isn't a requirement as it is likely I would also need to add a power supply to boost the signal from 3.3V to (likely) 24V for the relays (I have not found any DIN relays that will operate directly from GPIO).

https://blog.christophersmart.com/2016/ ... ct-part-3/

I'm open to suggestions, but not to use Z-Wave or Sonoff etc.

Additional notes:

Points regarding power and duty cycle of relays were raised on Geekzone. My current requirements are modest, 26W LED lighting. This is however a prototype for a future automation system so a 'complete' solution would allow for 100% duty cycle. E.g. the pool pumps currently require 1.5kW and can operate for 8+ hours a day in summer.
User avatar
gregmcc
Site Admin
Posts: 189
Joined: Sun Apr 12, 2020 4:45 pm
Answers: 0
Has thanked: 18 times
Been thanked: 49 times

Re: Controlling mains power with GPIO (In a compliant way)

Post by gregmcc »

there are already a number of home automation systems available off the shelf, no reason why with a bit of programing you couldn't make them talk to a R-Pi. You could re-invent the wheel and make get your own unit - A guy I worked for a while back built his house and done a Allen Bradley PLC, with HMI's around the house to control everything. It done the whole house lights, pool pump, under floor heating, HVAC. you could see temps of the hot water, of a particular room, open the garage door from any room etc. It all depends on how much time and money you want to put in to it.
SirHumphreyAppleby
Posts: 4
Joined: Mon Apr 13, 2020 8:34 am
Answers: 0
Has thanked: 0
Been thanked: 0

Re: Controlling mains power with GPIO (In a compliant way)

Post by SirHumphreyAppleby »

The trouble with off-the-shelf solutions is they tend to be short-lived. In five years time I'll be faced with integrating a new solution because parts are no longer available and possibly replacing components that no longer play nicely (E.g. libraries that won't compile on new kernel versions). I'm not looking at interfacing automation systems with a Pi, I'm trying to avoid any solution which I can't fix with readily available components.

My requirement really is just as simple as switching 230V AC with 3.3V, legally. Initially, I intend to use NodeRED and MQTT on the backend. The Pis will run my own MQTT implementation and only act as I/O devices. The entire system therefore will have no dependency on future support from any hardware or software vendor.

I have a relay from AliExpress ($US1.68 including shipping) that does everything I need. It accepts logic level input and uses an optional external power source (5V in this case) to switch the relays. The problem is, it is by no means a compliant solution. I don't mind spending money on quality components and enclosures necessary to do something similar in a compliant way, I just need some advice to establish what those requirements are.

I note some of the Sonoff products have been certified in Australia. They're pretty basic devices which are little more than a micro-controller and a relay, and they manage to comply. PLCs are interesting, but that's a somewhat over-engineered and expensive solution to what superficially at least appears to be a simple problem.
medistat
Posts: 19
Joined: Tue Apr 14, 2020 12:27 pm
Answers: 0
Has thanked: 0
Been thanked: 0

Re: Controlling mains power with GPIO (In a compliant way)

Post by medistat »

Sir Humphrey - have faced the same issues. My solution has been to extensively use the likes of these: https://www.controlbyweb.com/webrelay-quad/

I have extensive software development experience and as these devices are all on the same network, can access them to switch or sense them. In terms of sensing, they have digital inputs (door open/closed, pushbutton pressed.. etc) and analogue inputs (thermocouples, humidity, pressure, temp sensors) and so all manner of data can be sensed.

So yes, an off-the-shelf solution is a shitty quick fix but the limitations are why I have gone for the above devices and developed my own software.

Each 'zone' or 'job' is dealt with individually and the software has a separate 'rules' file that integrates one zone with another. Some examples are: my partner is a glass artist and her studio is 200m away from our house. So after a days work, her product needs to sit in a kiln at 800C then be ramped down by 20C every 30 minutes. Previously she had to run backwards and forwards all night but now, the webreley has a thermocouple and thru the code running via the network can act as a thermostat and switch the kiln on and off. As the kiln is 8kw, that is done by having installed an Omron G3PB SSR onto the board that switches the 32A socket supplying the kiln.

Another example is our security gate. The MhouseKit SLS10SC drive motor has a series of momentary-contacts to perform the various opens/close jobs so the webrelay is used to do those jobs. I have a series of ip cameras running iSpy and have the number-plate recognition software spewing out any plates that come down the driveway. If a valid plate is found, my software tells the webrelay to open the gate and the same process happens when the vehicle exits.

So once you have the basics in place and have an understanding of software development, the sky is the limit. Of course the other advantage is that every event can be logged.
Post Reply