Niall’s virtual diary archives – Friday 03 September 2021

by . Last updated .

Friday 3 September 2021: 11:57. I’ve made a start building prototypes of the Home Automation described in the first post of in the series about my future house build. This is my prototype, hand made, cove lighting:

My hand made cove lighting prototype

This is five metres of 120/m density 3000K warm white > 95 CRI (Colour Rendering Index) 2835 LED strip mounted into an alumnimum heat sink and diffuser firing along the direction of the ceiling. To shield the eye from glare and to make it look pretty, standard polystyrene coving runs underneath (glued to wooden mounts to prevent the LED heatsink melting the polystyrene), leaving a gap of about 1.0 - 1.5 cm along the top (it varies because the roof plaster varies in thickness). The heatsinking sits about 1mm from the wall, and air can flow from underneath around the back and out the top. This is 24v DC LED strip, which is unusual as most comes in 12v or especially 5v, but as a result it doesn’t draw more than 3A which makes for much less brightness fade along the strip, and less thick wiring needed – power injection every five metres is eminently doable with 24v LED strip, rather than the more usual one metre if say you had 5v LED strip. This saves an awful lot of time and hassle by reducing to one fifth the amount of wiring you need to do. The strip achieves > 95 CRI by randomly varying the colour temperature of each LED mounted on the strip such that the average comes out at 3000K, this creates a very nice light indeed, far better quality than your typical household LED bulb which may have a CRI less than 80. Indeed, this exact type of strip is more typically used for illuminating artwork in a gallery – it is total overkill for household lighting, and in practicality we probably will in the end use a cheaper LED strip as this stuff costs 60% more than say a CRI 90 strip.

In case you’re in the market for high quality LED strip, the vendor is Gree Lamps on Aliexpress run by a lady called Lucia. I was very pleasantly surprised during testing that my LED strip exactly matched her description, which is very rare for Aliexpress vendors who tend to inflate specifications. She is expensive compared to others, but what you get is spot on in terms of spec, power consumption, and quality. It’s very noticeable the difference between the light quality from this strip and our ceiling light, a Philips ‘high CRI’ LED bulb.

Having lived with the cove lighting for a good few weeks, we decided that we really like it. Much better quality of room illumination than ceiling point lighting. It’s really quite subtle the difference, and initially you don’t see it and feel underwhelmed. But after you get used to it, well, you become quite sold on this being the only possible lighting for your house.

To that end, we need to automate it, because on full this stuff consumes ~12w/metre or so, and thus my five metres here is ~60w which is the same as an incandescent bulb! Indeed, my ceiling point light only consumes ~15w, so this is consuming 4x more power and it only covers half the room! So we are going to need to dynamically dim this stuff using Pulse Width Modulation (PWM) based on proximity of humans i.e. each strip would be brighter the closer a human is sitting to it, and as you move around, the lighting automatically brightens around you as you move. This, in turn, keeps the electricity bill down, and obviously rooms without people automatically go dark. We can also have this stuff only illuminate barely in the middle of the night, so when you’re going to the toilet, it won’t blast you with so much light that it interrupts your sleep.

All that said, in order to not be anti social to human beings, the wall light switches still need to do something, so if somebody turns off a wall light switch, it ought to turn off the lights and/or change their brightness. And I want conventional light switches here, it needs to appear to not be fancy as that too would be anti-social.

Choosing your automation hardware

Home Assistant integration is an absolute hard requirement here. So most of the proprietary home automation systems are therefore out. I don’t like Wifi for anything reliable, I want everything on Ethernet, ideally PoE. I also don’t want to spend much money, but as well I don’t want to spend much of my precious little free time, which includes that I’d like to never have to maintain the thing if possible over the years to come. What I want needs to be cheap, but safe, and if one can spend a little extra to save my precious free time, I’ll spend it.

Most people in the enthusiast community would choose something like a Raspberry Pi Model B+. It has an ethernet port with add-on PoE hat, a wide range of i/o, it’s cheap enough at maybe €30 inc VAT for the Model B+ (or for the exact same money you can get instead the rather impressive Orange Pi Zero 2 which I very seriously pondered going with). However, for switching things with useful current and voltage you need to wire relays into the GPIO, and whilst those are cheap enough (maybe €1 per pair of 10A relays capable of being switched at 3.3v), you also would be wise to fit protection circuitry between the relay and the rather sensitive 3.3v TTL GPIO on the CPU, as if it ever saw more than 3.5v for even a fraction of a moment it would blow the port or maybe the whole CPU. It’s also a fair bit of hassle to wire up a relay if you want to have it powered by an independent loop – fine if you’re doing one or two, painful if you’re doing dozens. I am also not entirely trusting of cheap Chinese relays, I would view their claims of 10A with suspicion – maybe 7A is more like reality. I’m also mindful that all this stuff can catch fire if it shorts, though I’ll be fitting inline car fuses to hopefully prevent that.

Now don’t get me wrong: via RaspPi hats you can add everything I listed above in one convenient bundle. But a decent hat costs a good €45 inc VAT, so now you’re spending €75 inc VAT. And for just a little more than €75 there is a whole world of alternative options.

Why decent hats cost more than the board is because these little enthusiast boards aren’t really designed for rough environments e.g. hanging off long cable runs containing varying quality of voltages in a dusty corner. They are mostly mobile phone SoCs or cut down derivatives thereof – they were designed to be behind a decent PSU or a battery supplying a stable, regulated power and that almost all of what they deal with is the same e.g. Ethernet, a phone line, a satellite LNB, and so on, all with tightly bounded voltages and lack of EM noise. They are chalk and cheese to industrial CPUs like the ones in your car, or in factory plant where the CPU would be designed to tolerate sudden voltage droops of maybe 30% or spikes of maybe 10%, or for inputs to be 5v instead of 3.3v because a lot of industrial equipment uses 5v. What you swap with these industrial facing CPUs is clock speed, so where a 700Mhz CPU might be absolute rock bottom for those enthusiast boards, in order to tolerate voltage ripples you might expect one tenth of that in an industrial CPU. Your washing machine, for example, may well be running a 48Mhz CPU which constantly endures PF spikes from motors and switches turning on and off, but because it’s running so slowly, it don’t care. In the end, so long as your washing machine works, who cares if it runs at 48Mhz?

To that end I went looking for something more affordable than industrial boards, like say the cheapest National Instruments eight relay with Ethernet system I could find which costs a mere €1,500 inc VAT and total proprietary lock-in. A well known cheaper alternative to National Instruments is National Control Devices, a four relay system of theirs starts from €250 inc VAT onwards and a four MOSFET system of theirs starts from around €300 inc VAT onwards. But far cheaper again are boards from a small British company called Devantech, who have been making for many of the past thirty years now a bunch of Ethernet connected relay and GPIO boards out of industrial grade components for very reasonable prices if compared to NI or NCD. Despite being encumbered by Brexit, Devantech boards are very widely available all over the world via local resellers – the United States has an agent, as does Germany, as even does Iran. With a bit of searching, their local distributor can be found pretty much anywhere in the world.

Devantech provide two variants of their ethernet connected boards: (i) the traditional NI/NCD type boards which are generally fixed function and require an externally connected device to tell the board what to do or (ii) where the board has software defined function, using a custom programming language designed by Devantech called dScript, and whose programming manual can be found here.

Now this scriptability intrigued me. Obviously by now I had done an enormous amount of research, mostly involving ruling things and options out. Looking through the dScript manual I came to feel that these variants were worth the punt: 99% of the Home Automation I needed to do was totally doable on a 8Mhz ARM2 CPU which was the Acorn A3000 CPU back around 1990, so on anything similar or better, it ought to be a cinch. Morever, because this stuff is scriptable, for those 1% of situations where the local board can’t make a decision, it can explicitly do an upcall to Home Assistant and ask for direction because dScript lets you send and receive TCP or UDP messages.

The current range of Devantech dScript capable boards are these. All include USB 2.0 and 10-100 Ethernet, and they’ll accept an unregulated 12v DC input (i.e. I can use a cheap chinese PoE 12v splitter and not worry about the 12v DC quality):

ModelApprox price
(inc VAT)
Digital inputs
and outputs
(12v DC)
Other notes
dS1242€5924x VFC input or NPN output2x 10-bit1x TTL8x 32-bit trigger, 20 Hz input count80Mhz PIC32MX795F512H
512Kb128Kb6WSoC datasheet says there are five not eight counters
dS3484€7548x VFC input or NPN output4x 10-bit2x TTL, 1x RS4858x 32-bit trigger, 20 Hz input count80Mhz PIC32MX795F512L
512Kb128Kb12WSoC datasheet says there are five not eight counters
dS378€8887x software defined i/o, your choice of VFC input, NPN output or 10-bit ADC input2x TTL, 1x RS4858x 32-bit trigger, 20 Hz input count120Mhz PIC32MK0512GPK064? (guessed)512Kb?128Kb?12WHas seven ADC inputs, but datasheet for guessed SoC says 12-bit ADC. Also no Ethernet in the PIC32MK. So maybe a PIC32MZ?
dS2824€147 - €186248x software defined i/o, your choice of VFC input, NPN output or 12-bit ADC input1x TTL, 1x RS4858x 32-bit trigger, 10 Hz input count200Mhz PIC32MZ0512EFE064? (guessed)512Kb?128Kb?18WOptional integrated relay snubbers for inductive loads. Guessed SoC datasheet says there are four not eight counters
dS2832€184 - €233328x software defined i/o, your choice of VFC input, NPN output or 12-bit ADC input1x TTL, 1x RS4858x 32-bit trigger, 10 Hz input count200Mhz PIC32MZ0512EFE064? (guessed)512Kb?128Kb?24WOptional integrated relay snubbers for inductive loads. Guessed SoC datasheet says there are four not eight counters

Firstly, note that the Devantech 4-relay board is about one quarter the cost of its equivalent NCD board, and the 8-relay board is about one seventeenth the cost of its equivalent NI system. You might think that they reduced the quality of components to achieve that, and in some ways this is true: the NCD boards have 20A relays whereas the Devantech boards have 16A relays. Both are 12v industrial grade relays however, not the usually lower quality 5v relays in the RaspPi hats and cheap chinese relay boards. And in Europe, with our 230v AC versus US 115v AC, 16A relays are worth 32A relays in the US, so we here in Europe really don’t need 20A relays when almost all our AC use cases are bound by a 13A fuse in any case.

It is true that comparing the NI boards to anything else isn’t really comparative. I saw the NI boards in action during my work on the EuroFighter project back in year 2000 and there is no denying their extreme robustness. Sure, they cost a fortune, but they are built like a nuclear bunker compared to their cheaper competitors.

It is also true that from Aliexpress and other places you can obtain cheap chinese ethernet relay boards for about 20% less money than the Devantech boards. Whilst you may accept their 10A relays (likely really 7A), multiple internet forums report that they don’t play well together on the same ethernet subnet because they have a borked firmware. I have found no reports that the Devantech boards and firmware have any such issues. So if you’ll only ever use a single board, the cheap chinese alternatives might be worth a look, otherwise I’m fairly confident that the Devantech boards are about as good as you’re going to find for the price-feature benefit.

Secondly, there is a lot of guesswork in the table above, so until the board actually arrives and I can examine what’s on it, treat everything above with a pinch of salt, though note the link above that confirms that the dS3484 uses a PIC32MX795F512L. I will say that the cheapest Euro denominated reseller of Devantech kit I could find was Dutch, they’re a good 10% cheaper than most of the other Euro denominated resellers, and that’s from where I bought my board for prototyping.

Thirdly, the NCD board almost certainly uses a PIC32 processor just the same as the Devantech board does – maybe even a similar model. The PIC is, of course, the classic industrial CPU for many decades now. It is very hardy, accepting gladly really poor quality power supplies, and comes with oodles of relatively sophisticated i/o, like ample Analogue to Digital (ADC) inputs which you won’t find built-in on any mobile phone or PC facing CPU. However the PIC 32 CPU is not at all like the PIC chips of yore, which had a reputation of being horrible, and deservedly so in my opinion. The PIC 32 is really a MIPS chip, which is a very very good thing compared to that god awful PIC 8, which is probably the worst CPU I’ve ever seen in my career. The PIC 32, being MIPS, is quite sane and logical. No it ain’t no powerhouse, that there 80Mhz of clock speed gets you almost nothing compared to any desktop or mobile CPU, even an 80Mhz ARM Cortex A53 would run rings around it, but for my needs of ‘if this then that’ it ought to be sufficient.

The dScript manual claims that individual dScript instructions can scale between 40k per second and 400k per second, with 100k per second being a reasonable average assumption. On that basis, assuming that the built-in PWM hardware of the PIC32MX795F512L isn’t available to dScript so I’ll have to toggle outputs manually, I certainly think that 10Khz PWM is doable. This might not be quite enough to prevent flicker from the LED strips on a mobile phone camera, but once I get the board in my hands and have a go off it, I’ll see how far I can push it.

I have submitted a support request to Devantech to ask about less-than-1ms support in dScript, which from the dScript manual appears to be lacking. I’ll report back here in a subsequent post what they respond with.


Go back to the archive index Go back to the latest entries

Contact the webmaster: Niall Douglas @ webmaster2<at symbol> (Last updated: 2021-09-03 11:57:52 +0000 UTC)