Welcome to ned Productions

by . Last updated .

Welcome to ned Productions (non-commercial personal website, for commercial company see ned Productions Limited). Please choose an item you are interested in on the left hand side, or continue down for Niall’s virtual diary.

Niall’s virtual diary:

Started all the way back in 1998 when there was no word “blog” yet, hence “virtual diary”.

Original content has undergone multiple conversions Microsoft FrontPage => Microsoft Expression Web, legacy HTML tag soup => XHTML, XHTML => Markdown, and with a ‘various codepages’ => UTF-8 conversion for good measure. Some content, especially the older stuff, may not have entirely survived intact.

You can find the posts here replicated onto Diaspora, if you prefer to subscribe there instead.

Latest entries: Feed icon

Sunday 17 October 2021: 23:08. For several recent posts now in my series on my future house build I have been hoping to implement a custom Home Assistant integration for the custom logic I wrote in my keenly priced industrial grade scriptable PIC32-based Devantech dS3484 ethernet relay and input board. Last post three weeks ago I said I was feeling pretty burned out from all this post-day-job work, so I was going to take a weekend off, which I did. Alas, I then fell ill that following week, sufficiently badly that I had to take a few days off work, which is unusual for me. Since then I’ve been feeling rather under the weather, such that come end of day, I just go to bed, and similar early nights at weekends. This has made progress glacial.

Despite feeling crappy yesterday, today I was feeling energetic enough to finish off that custom integration for Home Assistant, and to write this virtual diary entry. The custom integration is a bit different to most Home Assistant integrations in that it asks the board what sensors and knobs it exports, and it then dynamically configures those items in Home Assistant according to whatever the board tells it. The custom integration starts off initially with a polling based update mechanism, but it asks the board for push subscription, and if the board says it supports that then the Home Assistant integration switches to push updates. From everything I can tell from Google, nobody appears to have implemented an entirely dynamic Home Assistant integration like this before, so I intend to properly write it up here and exactly how each bit of it works, for the benefit of everybody else on the internet, because it would save others several very late nights with coffee figuring this stuff out from first principles. Anyway, here’s the custom integration with push notifications in action – the potentiometer simulates a dimming switch, and my custom logic on the Devantech board appropriately dims the overhead LED strip cove lighting, but now ALSO pushes updates to any subscribed client. That, in turn, means Home Assistant is dynamically updated:

So that’s definitely working quite well then. I also updated the HTML dashboard published by my custom logic on the Devantech board to show push subscription details:

It’ll take me a week or two to write everything up properly, so watch this space!

Incidentally, for the past month the LED cove lighting automated by the Devantech board has become ‘the’ lighting for the main living space. It fades itself in when it gets dark outside, fades itself out when it gets light, automatically turns on when a person enters the room at night, turns off when no movement has been detected for five minutes. Everybody in the family likes the new ‘smart light’ a great deal, especially my son Henry who being a bit short struggled to turn on the light switch downstairs in the morning, and now he walks in and it turns on automatically. He’s very pleased with the improvement.


Last post I did a survey of the market for cheaper home automation with ethernet solutions and I settled upon the STM32F401 + W5500 as my ethernet microcontroller approach for €12 inc VAT each and the Raspberry Pi Zero + USB2 to Fast Ethernet as my ethernet microcomputer approach for €20 inc VAT. I mentioned in that post that the ESP32 is considerably more bang for the buck, if you can put up with its shortcomings in implementation quality. I thought that instead of assuming, I really ought to empirically test my assumptions, so I bought this, or rather, these:

This is an ESP32 wrapped into an Arduino compatible board for a mere €4.55 inc VAT delivered, which is a good bit cheaper than even the STM32F4 clone. Paired with it is a W5100 Ethernet shield for Arduino – or rather, a Chinese clone of the real thing (more later) – costing ~€11.50 inc VAT delivered, so the pair cost me €16 inc VAT. For this money, I get 250Mhz clock speed, 512Kb RAM, 4Mb flash, 11n Wifi, BT 4.2 and lots of flexible i/o, albeit that the Arduino compatible wiring limits me a lot on this. To my knowledge, there is only one prebuilt presoldered ready-to-go board cheaper than this with ethernet: the WT32-ETH01 which can be found for ~€14 inc VAT delivered, and my combination would appear to be better bang for the buck: same microcontroller but with proper power in socket, USB socket, existing Arduino IDE support – surely worth the extra €2 right?

Unfortunately, according to https://reedpaper.wordpress.com/2018/09/17/arduino-ethernet-w5100-how-to-fix-the-wrong-board/, the Chinese clone of the W5100 Arduino Ethernet shield has a wrong sized resistor on the ethernet port – it’s about 10x too big. This substantially weakens the signal on the LAN meaning you can’t use ethernet cables of any length without replacing the resistor. Using the information on that blog post, I have confirmed that my Shield is similarly flawed. So I suspect that apart from maybe a bit of poking at it to see how an ESP32 works in practice, this is probably €16 wasted, which is annoying. Had I known this before ordering, the WT32-ETH01 would have been my choice.

Anyway, I’ve received all the parts I spoke about last diary entry, but I discovered that the camera cable for the Zero is narrower than that for any other Pi board – thanks so much to whomever made that design choice, especially as the Zero board has enough space for the same connector as all the Pi boards. So I had to order special cables which connect the Zero’s narrow camera connector to standard camera connector. Those are still en route from China, and seeing as I’ve not been well anyway, I’ve done very little with all the new hardware yet apart from boot up Raspbian and get the Zero to hardware PWM dim a small LED via a MOSFET (and yeah hardware PWM is orders of magnitude better quality than software PWM, even on a 1Ghz CPU like the Zero’s).

Another thing that I need to do is port the ST time of flight software library to RaspPi, I bought the fancy software defined function ST VL52L3CX ToF sensor which basically returns raw data and you need a fairly substantial CPU plus the ST software library to interpret what the laser can see by doing lots of floating point math. The Raspberry Pi Zero is easily powerful enough, but no port of ST’s library to Linux exists yet as far as I can tell, though from inspection of the source code the port will be trivially easy. Anyway, once working, you should be able to ‘see’ everything within five metres of the sensor’s fifteen degree field of view, which is to say it yields (and I am paraphrasing here) how much of its view is obscured at what distance e.g. 10% of it is blocked at 1.0m, a separate 20% is blocked at 4.0m, and so on. It’s accurate down to the millimetre, and can tell when things have changed in its view i.e. it can take a sample of ‘empty room’, and tell when ‘empty room’ gains a new thing within it which doesn’t belong, and both how far that new thing is from the sensor AND how big it is. In other words, it should be able to tell when a human has entered a room, and whether that human is sitting or standing or lying down. I am hoping to use these instead of cameras for the bedrooms to detect the difference between an occupant sleeping in their bed, sitting up in their bed, and vacated their bed. We’ll see how empirical testing goes.


Finally, you may remember when I installed HEPA filters in multiple rooms throughout the house to improve the air quality in this quite mouldy and damp house with the added benefit of scrubbing the air of virus particles, such that the kids bringing covid home from school might not infect us adults quite as quickly. Those Xiaomi Air Purifier 3C’s which I automated with a Python script have proven themselves to be excellent – still no rattle off them, they are quiet and efficient and judging from the amount of lint they collect, they are plenty effective too.

The kitchen purifier gets by far the worst of it as it regularly has to spin up to maximum to scrub the air of PM2.5 generated by cooking. I noticed the grille on the top where the clean air comes out was getting dirty, so obviously the filter had become spent – unsurprising after eight months of cooking! So I replaced the filter (Xiaomi very helpfully place OEM replacement filters on German Amazon at RRP prices which are cheaper than Aliexpress prices, though they do go out of stock very quickly after new supply arrives), and that left me with a dirty filter heading for the trash.

So I, probably like all of you, was wondering what these Xiaomi filters look like on the inside, and just how dirty is this filter? So I cut it open to have a look:

The first layer after the outer plastic grille is a dense paper-like filter thickly folded in concertina. A brand new filter has dark grey outside and I would assume a clean white inside -- this filter has mottled grey outside and obvious discoloration inside. The concertina folding is held taut by a tensioned rubber string which is actually glue, very clever.

Peeling back the densely woven filter material:

Held in a dispersed lattice after the filter materials are granules of activated carbon arranged with holes in the middle.

As mentioned in the original post, the grey filter is Xiaomi’s highest end filter with a claimed HEPA specification of 99.95% efficiency. Unlike the EPA purple or green filters which have added filtration layers for other pollutants, the grey filter is more like the basic EPA blue filter: just activated carbon and filter, nothing extra. The +29% price difference (€31 inc VAT delivered for the blue filter, I paid ~€40 inc VAT delivered for the grey filter from Amazon Germany) reflects the difference in quality of filter material only, with no difference in feature set apart from claimed 10x better filtration efficiency.

As much as €40 for a filter seems a lot (about half the price of the entire purifier unit itself!), having cut one of these open I was impressed by its heft and quality – in fact, cutting it open took quite a bit more effort than you would think so dense are the materials. The way they’ve arranged the activated carbon granules in that pattern and with cleverly differently sized pores in the multiple layers of plastic mesh aids slow moving air ingressing past the filter material to hang around the activated carbon for a bit longer before getting sucked up and out. I’ve no idea how these filters compare in quality or effectiveness to ‘western’ filters, but in terms of what I think a HEPA filter ought to be these subjectively tick all the boxes. I also like that they’re simple and yet so clever: that’s the mark of good design.

I have four purifier units in total in the house, and I intend to replace their filters around the twelve month mark as they don’t receive anything like the gunk the kitchen purifier receives. As I was remarking to Megan last night, Xiaomi do a really great job of making consumer goods 80%-90% as good as western brands but for 50% of the price. We’ve now got smart watches, robot vacuum cleaners and air purifiers from Xiaomi or its subsiduary brands and we find them all so far to be excellent value for money, and we really like that Xiaomi makes available spare parts AND makes their stuff easily maintainable as a matter of course. Indeed, we only wish that Western manufacturers took more of a leaf from Xiaomi’s book – and if they continue to fleece the Western consumer with unmaintainable, expensive, products with built-in hard coded death times, then Xiaomi is going to supplant and replace them, and rightly so.

#house #home-assistant #air-purifiers #xiaomi




Sunday 26 September 2021: 23:11. In the last post in my series on my future house build I had hoped to get a custom Home Assistant integration implemented this weekend for the custom logic I wrote in its proprietary language dScript for my keenly priced industrial grade scriptable PIC32-based Devantech dS3484 ethernet relay and input board. I can say that its learning curve was too steep for me to conquer this weekend – though I made excellent progress and it’s just a question of more time to finish it – but ultimately there is only so much completely new material that one can grok through and master after midnight, even after drinking coffee (I honestly can’t think of the last time I drank coffee so late in the day, but it really was needed if I was to make any decent attempt at all that Home Assistant programming documentation).

Anyway, once finished that will be the topic of a future post here in the series. This post is more about what prototyping and empirical testing needs to come next after the Devantech board. Firstly, I want to be clear that my experience with the Devantech board has been very positive. Yes its dScript language definitely could do with a lot more polish – there are a lot of weird things missing or syntax not permitted for no obvious reason – I suspect a single person designed and implemented it, and it has never received much feedback which was acted upon with respect to the programming language itself. Still, it’s definitely powerful enough to get almost any job done – for this Home Assistant integration I am writing I created a small TCPIP control server in dScript which was quite straightforward, as was getting it to push state change updates to any arbitrary third party IP address which registers with it. Implementing that part took only an hour or so, what I got bogged down in this weekend was Home Assistant programming itself.

Still, the Devantech board isn’t the right solution to some of the things I need solving in my future home automation. Firstly, the lack of high frequency PWM was a showstopper for dimming the LED cove lighting in a quality way – the maximum 1Khz software PWM just isn’t enough. Secondly, there are a bunch of sensors I want to use which either can’t fit into the Devantech board (any I2C for example), or aren’t well suited to the volt free digital inputs (though note that the bigger Devantech boards do offer switchable volt free or TTL digital inputs, and I now wish I had bought one of those instead). Finally, these boards are way overkill for use cases not involving > 7A current loads, and as I’d expect we probably will need at least one board per two rooms, that’s excessively expensive given they’re about €100 inc VAT including case each. What I really want is one or two Devantech boards for the high current stuff, and something much cheaper everywhere else.

Cue thus lots, and lots, and lots of research to figure out a solution which can do:

  • high frequency PWM LED strip dimming.
  • can read light switch digital inputs.
  • have an I2C bus for ‘is there a person in this room’ sensing.
  • maybe an ADC for analogue sensors like temperature.
  • LAN connected.
  • PoE powered.
  • either no Wifi at all (security risk/spectrum interference), or can act as a decent enough local Wifi AP, which means ‘can run OpenWRT and can at least do 2x2 11ac (Wifi 5, 866 Mbps) and have true Gigabit Ethernet’.

And obviously do all of this for as cheap as possible both in terms of money and my precious free time in wiring it all up, commissioning it, and maintaining it!

Survey of the market as of Q3 2021

I went through many options: all the Small Board Computers (Raspberry Pi, Rock Pi, Orange Pi, NanoPi etc), all the Microcontrollers (PIC32, ESP32, STM32 etc), dedicated PWM boards, adapting Wifi AP boards to do GPIO. So I can say something about the current cost-benefit balance and tradeoffs in the market as of Q3 2021.

Firstly, the absolute cheapest board capable of true Gigabit Ethernet and 11ac Wifi is the Orange Pi Zero 2 currently going for €30 inc VAT for the board and €5 inc VAT for a 16Gb sdcard = €35 inc VAT. However it’s an Allwinner H616 chipset, it’s not well supported, and there are big question marks over its Wifi implementation quality.

The second cheapest is the venerable Raspberry Pi 4 Model B for €40 inc VAT, assuming you can find one in stock (I could not). It is Broadcom based, which isn’t the best story for being an AP under OpenWrt but thanks to its huge popularity it has been made to work. It has 1x1 11ac Wifi. You need €5 inc VAT for a 16Gb sdcard = €45 inc VAT.

The next cheapest is the Radxa Zero currently for €50 inc VAT, it’s Amlogic S905Y2 based so it’s got really really good software support (e.g. OpenWRT ‘just works’ on this board) and its Wifi AP implementation is excellent. It also has 8Gb of onboard flash saving me needing a sdcard. However it lacks an Ethernet port though it does have USB3, so you’d need to add a USB3 Gigabit ethernet adapter for €15 inc VAT, so it costs €65 inc VAT which is getting close to the Devantech board, and we still don’t have 2x2 Wifi, only 1x1 Wifi.

The next cheapest is the Rock Pi 3A currently for €57 inc VAT + €5 inc VAT for a 16Gb sdcard = €62 inc VAT. This has gigabit ethernet and two PCIe M.2 slots, so you can fit your own 2x2 Wifi card which is certainly another €20 inc VAT if you want Wifi 5 or another €40 inc VAT if you want Wifi 6, so now you’re at €82 - €102 inc VAT.

Add in a Gigabit PoE splitter for €15, and €100 per room is rather a lot of money when there are many rooms in the house.

So what about instead fitting fewer but better APs e.g. the TP-Link Mercusys MR70X is a 2x2 Wifi 6 AP with three gigabit ethernet ports for €45 inc VAT with an Amlogic chipset already with early OpenWRT support, share one of those between a few rooms each, and then per room fit something much much cheaper for the lights and sensors?

The choices for further testing

Out of all the microcontrollers and small board computers I calculated all the bits which would needed and these two are what I have chosen for further investigation:

  1. Microcontroller approach:

    • STM32F401: 84Mhz ARM Cortex M4F, 64Kb RAM, 256Kb flash. €5 inc VAT delivered. Nicknamed ‘the Black Pill’.
    • W5500 ethernet connected by SPI. €7 inc VAT delivered.

    Total: €12 inc VAT each

    Advantages:

    • Up to four hardware PWMs capable of > 20 Khz frequency, or up to five SPIs, or up to three I2Cs, or up to seven 12-bit ADCs, or up to twenty digital inputs or outputs.
    • No OS nor filesystem, so hard realtime, once debugged maintenance likely will be very low.
    • Arduino ecosystem available via STM32duino.
    • Cortex M4 is ARMv7 and there is even hardware single precision floating point, which is nice as you can avoid fixed precision integer arithmetic for say percentage calculations.

    Disadvantages:

    • I really can’t think of any, though I may find some once I actually use the board, and it’s been a LONG time since I last did work on a truly bootstrapped embedded microcontroller.


  2. Microcomputer approach:

    • Raspberry Pi Zero: 1Ghz ARM11, 512Mb RAM. €6 inc VAT.
    • USB2 to Fast Ethernet adapter. €9 inc VAT.
    • 16Gb micro sdcard for storage. €5 inc VAT.

    Total: €20 inc VAT each

    Advantages:

    • Up to two hardware PWMs capable of 250 Mhz frequency, or up to two SPIs, or up to one I2C, or up to twenty-four digital inputs or outputs.
    • Camera connector. And the GPU can hardware encode to h.264!
    • Full USB stack on USB ports, so anything USB is available to you.
    • Half the current cost of the cheapest Raspberry Pi with ethernet, the Raspberry Pi 1 Model B+ currently going for €30 inc VAT.
    • Passable hardware single and double floating point, which Raspbian jumps through a lot of hoops on your behalf to make it appear seamless.
    • Full Debian, so I have plenty of up to date experience using this.

    Disadvantages:

    • Despite how astonishing it is that you can nowadays get a full computer with full fat Linux for €20, it still costs 67% more than the Microcontroller option. Multipled many fold, that adds up.
    • No ADCs so no analogue inputs possible without additional hardware.
    • ARM11 (first gen ARMv6) is really ancient. Like twenty years old now. It’s full of weirdness and quirks, though Raspbian does a fabulous job at mostly papering over the cracks.
    • Runs a proper Linux and so will need security updates etc and other ongoing maintenance. It also won’t like sudden power loss much.

Why not the alternatives?

Why STM32F4 instead of Arduino? It’s simply a price-performance thing – that STM32F4 runs rings around an ATmega CPU, having orders of magnitude more RAM, Flash, performance, and being 32-bit not 8-bit, and having a modern C++ toolchain instead of a proprietary partial standard library compiler. Yes it costs 25% more – the STM32F4 is €5 delivered versus €4 inc VAT delivered for the ATmega – but am I going to sweat an extra euro here for how much more you get? No.

Why STM32F4 instead of ESP8266? For €3 inc VAT delivered – even less than the ATmega – you can get a comparable specification ESP-12E dev board, and for €2 more it can come with a really nice breakout adapter board which saves lots of hassle soldering. It also comes with built-in wifi and bluetooth, though only 2.4Ghz 11n, and I really have to hand it to Espressif that they’ve really thought through making it as nice as possible for people like me yet cheaper priced and better specced any other alternative. However whilst comparable in specification, there are fewer GPIOs, ADCs, I2Cs and so on which means I’d need to fit more them with more PoE power adapters which makes them more expensive overall.

Why STM32F4 instead of ESP32? This is much tougher to explain, because in most ways the ESP32 is far superior. Historically ESP32 cost a touch more and STM32 a touch less, so its better feature set was somewhat proportional to the cost increase. Recently though they’re both about €5 inc VAT delivered, and in most ways it’s not a fair fight: 3x faster clock speed, 2x more cores, 8x more flash, 8x more RAM, AND 11n Wifi and Bluetooth v4.2, plus up to sixteen PWMs, or up to five SPIs, or up to four I2Cs, or up to eighteen 12-bit ADCs, or up to thirty-four digital inputs or outputs – the ESP32 is a whole lot of microcontroller for the money.

But despite on feature set alone not being a contest, the STM32F4 still has a few big advantages:

  • It is ARM which has an enormous ecosystem, not Xtensa DSP which has not. This matters a lot – all my sensors have code examples, drivers or python modules written and tested on either ARM or ATmega, and usually both. Getting all of those working well on Xtensa with the current state of its ecosystem seems unlikely.

  • ESP32 makes better a lot of the quirks and surprises that were in ESP8266, but they’re not entirely gone. For example it still has non-linear and unstable ADCs, albeit less non-linear and unstable than the ESP8266, but you still get crappy resolution at the bottom and top i.e. they’re range constrained, a classic sign of a not fully mature solution, and they also experience a good bit of sampling and thermal noise normal ADCs do not. And it’s not just the ADCs which are quirky, ultimately Espressif just aren’t quite up there with the big boy league in terms of quality and predictability yet. Don’t get me wrong, they are constantly getting better, and every new product generation is another leap forward. But you’ll still be fighting their lack of ecosystem depth which just isn’t an issue if you’re on ARM.

  • Ultimately I don’t actually need all those features – I don’t have enough stuff to connect into them without running more cable than it’s worth. The STM32F4 has enough i/o for my use case, it also has enough RAM and enough flash. It’ll do.

If one day the ESP32 + RJ45 ethernet boards currently costing €15 inc VAT delivered came down to around €8 inc VAT, then I might see myself using ESP32 for various solutions e.g. it would be quite unbeatable for controlling irrigation in a greenhouse where accuracy isn’t so important. But at €15 the STM32F4 + RJ45 easily beats it at €12, even with the hassle of soldering and wiring.

Finally why the Raspberry Pi Zero? To be honest there is no close competitor at all in this choice of microcomputer – nothing else comes close to the bang for the buck you get for €6 inc VAT. Sure it’s two decade old and is quirks-ridden technology, but its ecosystem support is very, very deep and very, very wide. Even its Wifi edition which in my opinion is terrible value for what you get for doubling its price still has few good competitors for that price – the quality of the boards and their ecosystems on the market between the Zero W for €12 inc VAT and the Raspberry Pi 3 Model B for €30 inc VAT I don’t think are worth the money saved in terms of added hassle and working around poor QoI e.g. buggy USB stacks making your USB Ethernet dongle not work quite right.

Hybrid approach

You’re probably gathering that I’m currently favouring the Microcontroller approach, but I in fact expect to adopt a hybrid approach. Why? Well it’s that camera connector on the Raspberry Pi Zero, it means that I can fit to it a 5MP OV5647 camera with infra red lights for €10 inc VAT including delivery, thus saving me having to buy Hikvision cameras each costing €80-100 or so. Anywhere which is not a bedroom nor bathroom will have multiple cameras looking at it. This is partially for security, but it’s mainly because I believe I can estimate human motion and coordinates within a three dimensional reconstruction by combining images using something like https://github.com/alyssaq/reconstruction. This, in turn, means I don’t need to mount – and more importantly, not need to wire – distance sensors running along the walls to detect where people are within a room, and thus adjust the brightness of the lighting in that locality in order to conserve power (as my LED strips will consume rather a lot of power if fully bright).

There are, annoyingly, STM32F4 models also with a camera connector, but I don’t think the Chinese sell cheap clones of them yet. Also, even if I had a STM32 here, I very much doubt a ~200Mhz ARM CPU can do any meaningful compression on a 5MP video feed before it needs to be sent out on a SPI connected Fast Ethernet port, which at best probably can’t push more than 40Mbit, so that’s a max resolution of 1280x1024 @ 30fps (and likely less in practice). And even then, your Gigabit network will rapidly saturate with lots of 40Mbit video streams running along it. Whereas the original Raspberry Pi (which has the exact same SoC as the Zero) has h.264 hardware encoding, and for which there is a nice Python library to have the camera and video encoding acceleration hardware cooperate and write the output to a socket. It should be able to make at least Full HD @ 30fps for 8Mbit or so, and that seems to me a nice cost saving over standalone Hikvision cameras.

Thus, I expect Raspberry Pi Zeros in the public spaces wherever I also need a camera (approx three per space for triangulation), and Black Pills everywhere else including outdoors as they’re cheap and replaceable enough that I don’t need to care too much about them getting damp or full of spiders for example.

Conclusion

I have placed an order for both and a whole load of sensors for me to experiment with. Finding a Raspberry Pi Zero without wifi in stock for something approximating its proper price was tough, I ended up going with German BerryBase and they got it delivered with a bunch of sensors and cables where it was cheaper to get it from them than Aliexpress within a week for a good price. For the Black Pill and all the other sensors where after postage it was still cheaper, I went with Aliexpress and that’ll likely be in transit for a good few weeks yet.

After the next post likely on the custom Home Assistant integration, I’ll start testing sensors with the Raspberry Pi Zero and I’ll no doubt write a post on my experiences with each of those named by exact model number (I did a ton load of research choosing each of them very carefully). However next weekend I also intend to take a break from staying up until 4am doing this stuff, because I’m getting a bit sick of feeling like crap every weekend, and I’d like a break from the slog of it.

#house




Sunday 19 September 2021: 22:54. Last weekend in my series on my future house build, I looked at the physical board of the keenly priced industrial grade scriptable PIC32-based Devantech dS3484 ethernet relay and input board, and I got a demonstration LED being PWM dimmed using a small program written in its proprietary dScript programming language. This weekend my goal was to get an actual solution to automating my prototype cove lighting up and working, including user selectable PWM dimming and automatic on-off based on outdoor brightness and whether there is someone in the room.

Firstly let’s look at how I have wired up the board:

The Devantech dS3484 board controlling a 24v AC power supply and MOSFET to PWM dim the LED strip

My LED strip is 24v, so that AC power supply is a 24v model (the box taped to the top is a 24v to 12v buck converter for 12v LED strips to be added later). Both its live and neutral have been wired into the first two 16A relays of the Devantech board. Hanging between the 24v power supply and the board and the LED strip is a cheap chinese clone of an IRF520 MOSFET costing barely one euro which is claimed to be able to handle up to 5A, but as a clone I’d not trust it with more than 3A (and indeed my 24v LED strip can draw an absolute max of 3A, which is not a coincidence). You’ll note that I added inline 5A car fuses for both the 12v buck converter and the supply to the IRF520 clone, just in case, and since that photo was taken I have added a heatsink to the MOSFET, because those IRF520 clones do run hot even on half their claimed amperage.

The IRF520 clone will switch at around 3v, so I wired the 5v output from one of the analogue inputs on the Devantech board to power the MOSFET, and using a 470 Ohm resistor I routed the same 5v supply via a digital i/o and in parallel to the MOSFET. This is because the Devantech digital i/o are NPN rather than the PNP typical in Arduino/RaspPi type boards, so when on they connect their input to ground, and when off they do not connect their input to ground (i.e. they don’t source, they sink). So, after the resistor, when off there is approximately 3.3v @ 10 mA remaining from the 5v input to switch the MOSFET on; when on that 3.3v gets drained to ground, switching the MOSFET off.

(Incidentally, due to doing all this stuff at ~2am after a full workday having risen at 7am, I foolishly shorted the resistor which delivered the full 5v to the digital i/o. The board, being i/o buffered and industrial grade, blew a small fuse on the individual digital i/o rather than blowing the board. That digital i/o no longer works, but it proves the quality of the board – had that been a Raspberry Pi, I’d have blown the chip)

Along the analogue inputs, I have connected a cheap TEMT6000 photoresistor which runs on 5v, outputting a 0-3.3v signal depending on how much visible light it sees (and I taped it to the room’s window). Next is a potentiometer, to simulate a wall rotary dimming dial which are just potentiometers wired into a triac (if you snip the internal connection and wire in a DC cable to the potentiometer, you can use an ordinary wall dimming dial switch very nicely). Finally, I wired a cheap HC-SR501 PIR sensor into analogue, despite it being a digital i/o, because the Devantech board’s digitial inputs are volt free, meaning you can connect up any voltage you like within spec (I assume <= 12v?), and the input will sense a 0-2v difference from ground as a zero and anything more as a one. Volt free is great for most uses cases e.g. just connect a physical switch, no power needed, the input ‘just works’. But when the input is a TTL device, the problem is when the signal is zero it isn’t connected to ground in a way the volt free input can detect (it basically needs a small current to flow, and none does), so the Devantech digital input can’t work with TTL inputs without additional circuitry. Whereas the analogue input ‘just works’ here, albeit you’ll need to poll it for new values. Luckily, this particular PIR sensor holds its digital signal high for three seconds per detection, so if you poll the analogue input every second or so, you’ll definitely catch it.

Last night I wrote this somewhat more complex than the last time dScript program to run it all:

digitalport LED_STRIP_PSU_RELAY1 1 ; relay 1
digitalport LED_STRIP_PSU_RELAY2 2 ; relay 2
digitalport LED_STRIP_PWM_DIMMING_IO 47  ; i/o 7
analogport LED_STRIP_PWN_DIMMING_SELECT_IO 4  ; analogue 4
analogport PIR_SENSOR_IO 1  ; analogue 1
analogport WINDOW_LIGHT_SENSOR_IO 3  ; analogue 3
const TICKS_BETWEEN_DIMMING_LEVELS 500
const TICKS_BETWEEN_PIR_SENSOR 300000


; Increments monotonically at 1000Hz
int32 monotonic_count

; The current LED strip dimming. 0 = off, 8 = 100%
int8 led_strip_dimming_level_actual
; The desired LED strip dimming
int8 led_strip_dimming_level_wanted
int32 led_strip_dimming_level_wanted_ticks_remaining
; The last time we saw PIR movement
int32 last_pir_movement_monotonic_count

function set_led_strip_dimming_level(int8 newlevel)
  if newlevel != led_strip_dimming_level_wanted then
    if led_strip_dimming_level_wanted == 0 and led_strip_dimming_level_actual == 0 and newlevel >= 4 then
      ; fast start straight to 50%, spool up from there
      led_strip_dimming_level_wanted = 4
      led_strip_dimming_level_actual = 4
      software_pwm_dimmer_impl()
      threadsleep 250
      if newlevel == 8 then
        led_strip_dimming_level_wanted = 8
        led_strip_dimming_level_actual = 8
        software_pwm_dimmer_impl()
      endif
    endif
    led_strip_dimming_level_wanted = newlevel
    if newlevel != led_strip_dimming_level_actual
      led_strip_dimming_level_wanted_ticks_remaining = TICKS_BETWEEN_DIMMING_LEVELS
    endif
  endif
endfunction

int32 last_pir_movement_delta_returned
function int32 last_pir_movement_delta()
  int32 ret
  ret = monotonic_count - last_pir_movement_monotonic_count
  if ret < 0 then
    ret+= 2147483647
  endif
  last_pir_movement_delta_returned = ret
  return ret
endfunction

; Implements LED strip PWM dimming
; The i/o when on turns the lights off, so this is inverted
function software_pwm_dimmer_impl()
  int32 todo
  ; In case you're wondering why not compare the masked value to something to
  ; set todo as a boolean, dScript doesn't support comparison operations in
  ; variable expressions. No that makes no sense at all :(
  select led_strip_dimming_level_actual
    case 0 ; 0%
      todo = 1
    case 1 ; 12.5%, 125Hz
      todo = (monotonic_count & 7)
    case 2 ; 25%, 250Hz
      todo = (monotonic_count & 3)
    case 3 ; 37.5%, 125Hz
      todo = (monotonic_count & 7) - 2
    case 4 ; 50%, 500Hz
      todo = (monotonic_count & 1)
    case 5 ; 62.5%, 125Hz
      todo = (monotonic_count & 7) - 4
    case 6 ; 75%, 250Hz
      todo = (monotonic_count & 3) - 2
    case 7 ; 87.5%, 125Hz
      todo = (monotonic_count & 7) - 6
    case 8 ; 100%
      todo = 0
   endselect    
   if todo > 0 then
      LED_STRIP_PWM_DIMMING_IO = on
   else
      LED_STRIP_PWM_DIMMING_IO = off
   endif     
endfunction

; Turns the LED strip on
function turn_on_led_strip()
  if LED_STRIP_PSU_RELAY1 == 0 then
    ; Set the MOSFET off
    led_strip_dimming_level_actual = 0
    led_strip_dimming_level_wanted = 0
    software_pwm_dimmer_impl()
    ; Set relay 1 and then relay 2 on, wait for the PSU to initialise
    LED_STRIP_PSU_RELAY1 = on
    threadsleep 20
    LED_STRIP_PSU_RELAY2 = on
    threadsleep 105
  endif
endfunction

; Turns the LED strip off
function turn_off_led_strip()
  if LED_STRIP_PSU_RELAY1 == 1 then
    set_led_strip_dimming_level(0)
    do until led_strip_dimming_level_actual == 0
      threadsleep TICKS_BETWEEN_DIMMING_LEVELS
    loop
    ; Set relay 2 and then relay 1 off
    LED_STRIP_PSU_RELAY2 = off
    threadsleep 20
    LED_STRIP_PSU_RELAY1 = off
    threadsleep 20
  endif
endfunction

thread software_pwm_dimmer_tick(1)
  monotonic_count += 1
  if monotonic_count == 2147483647 then
    monotonic_count = 0
  endif
  if led_strip_dimming_level_actual != led_strip_dimming_level_wanted then
    led_strip_dimming_level_wanted_ticks_remaining -= 1
    if led_strip_dimming_level_wanted_ticks_remaining == 0 then
      if led_strip_dimming_level_wanted > led_strip_dimming_level_actual then
        led_strip_dimming_level_actual += 1
      else
        led_strip_dimming_level_actual -= 1
      endif
      if led_strip_dimming_level_actual != led_strip_dimming_level_wanted then
        led_strip_dimming_level_wanted_ticks_remaining = TICKS_BETWEEN_DIMMING_LEVELS
      endif
    endif
  endif
  software_pwm_dimmer_impl()
endthread


; This coroutine samples the analogue inputs, so we run it at 0.1Hz
int32 outside_brightness
;int32 board_temperature
thread pir_control_tick1(10000)
  outside_brightness = WINDOW_LIGHT_SENSOR_IO
  ;board_temperature = TS1
endthread

; This coroutine samples the analogue inputs, so we run it at 5Hz
int32 chosen_dimming
thread pir_control_tick2(200)
  int16 pir_movement
  pir_movement = PIR_SENSOR_IO
  if pir_movement >= 512 then
    last_pir_movement_monotonic_count = monotonic_count
  endif
  int32 delta
  delta = last_pir_movement_delta()
  ; If it is bright outside, or no movement at all for an hour, turn off the LED strip and we are done
  if outside_brightness >= 600 or delta > 1800000 then
    turn_off_led_strip()
    threadsuspend ; we are done
  endif
  ; If the whole unit is off, and it's dark outside, only switch on
  ; if there has been movement recently
  if LED_STRIP_PSU_RELAY1 == 0 then
    if outside_brightness <= 500 and delta < TICKS_BETWEEN_PIR_SENSOR then
      turn_on_led_strip()
      set_led_strip_dimming_level(8)
    else
      threadsuspend ; we are done
    endif
  endif
  ; Unit is on, decide what brightness it needs to be
  if delta < TICKS_BETWEEN_PIR_SENSOR then
    ; Set to whatever the potentiometer says
    chosen_dimming = LED_STRIP_PWN_DIMMING_SELECT_IO
    set_led_strip_dimming_level(1 + (chosen_dimming / 128))
    threadsuspend
  elseif delta < TICKS_BETWEEN_PIR_SENSOR + 10000 then
    set_led_strip_dimming_level(1)
    threadsuspend
  else
    set_led_strip_dimming_level(0)
    threadsuspend
  endif
endthread

thread main(const)
  ; upon boot, turn on LED strip immediately, but dim
  turn_on_led_strip()
  set_led_strip_dimming_level(1)
  threadstart software_pwm_dimmer_tick
  threadsleep 3000
  threadstart pir_control_tick1
  threadstart pir_control_tick2
endthread

Hopefully the above is fairly self explanatory with the comments explaining anything weird looking – basically we physically disconnect the 24v AC adapter whenever possible, but we keep it running for 30 minutes after nobody being in the room so lights can be quickly started within 100 ms if somebody enters. I took especial care to never do too much at a time in a coroutine to keep the software PWM smooth and thus the flicker as least obvious as possible – you will probably also note the hard coded eight possible PWM dimming level choices, which is probably the most practically possible with a 1Khz clock. Here’s a video of me cycling the dimming down and back up again using the potentiometer:

The 500Hz 50% dim seems to not flicker on the phone camera’s sensor, but the 250Hz and especially 125Hz levels do. As mentioned in previous posts, this isn’t the Devantech board’s forte – the hardware PWM of the PIC32MX chip isn’t available to dScript, and I think given this is an interpreted bytecode running on a 80Mhz CPU even achieving smooth 1Khz software PWM is pretty impressive. Speaking personally, I am rather flicker sensitive, and I can easily see flicker at 500Hz. I find it quite offputting, though it is a lot less worse than the 250Hz and 125Hz PWM – that latter looks to me like a light pulsing on and off. Meanwhile my wife couldn’t detect any flicker at all except a little at 125Hz PWM.

Finally, as I mentioned last post, these Devantech boards have the unique feature that they can serve a HTML page of your design with AJAX updating fields pulled from global variables in your dScript program. I didn’t go nuts here, I made a simple HTML table and had it fill in various values to make a simple status dashboard:

All in all apart from the occasional head scratch all this work went smoothly, albeit that the low resolution software PWM dimming isn’t really good enough for my house build, so I’ll need something better. I didn’t get around this weekend to integrating this with Home Assistant, so next weekend that’s exactly what I’ll be doing: I’ll probably write a very simple local push integration for Home Assistant that lets this dScript push status changes to Home Assistant. I may also allow Home Assistant to override the board’s default logic e.g. put lights to 100%, or turn everything off.

Something else I’ll need to make a start on is researching alternatives for home automation. Something rather noticeable in this prototype is basically all the analogue inputs are full already, and given each of these boards costs at least €75 inc VAT, that’s rather too much money to be expending per room in the house. I need something much cheaper which can also do high resolution hardware PWM dimming and isn’t a pain to wire up and/or configure. I’m also minded that I have a bunch of sensors I want to test for my house build which require I2C, and the Devantech board doesn’t expose that.

Don’t get me wrong here, this Devantech board is absolutely great for automating high current stuff such as immersions, pumps, home heating water valves, that sort of thing – anything involving 12v DC or 230v AC and lots of current. The volt free inputs are perfect for wall switches etc. but not suited for wiring in Arduino/RaspPi focused sensors. This implies that my sought after cheaper alternative probably is going to be an Arduino or Raspberry Pi, exactly because the whole breakout board sensor ecosystem is designed around them, but also because they have the deep software support for enthusiasts which makes the experience a whole lot less painful than is usually the case with embedded systems programming.

#house




Monday 13 September 2021: 01:25. I received my industrial quality Devantech dS3484 board which cost me €75 inc VAT, a fraction of near equivalent boards from National Control Devices or National Instruments, yet provides similar functionality and uses proper 12v powered industrial grade components same as they do. As I described in the last post on the topic of my future house build, this board is capable of running a proprietary BASIC-like scripting language called dScript which lets you program it to carry out a fair bit of local automation, thus reducing how much control complexity you need to encode into a network controller such as Home Assistant. As the last post mentioned, there is a lack of detail online about the Devantech boards, and whilst the Devantech website contains a board specification, description and you can glean more detail from its dScript programming manual, there is a definitely lack of subjective user experience of these boards i.e. people who have had a go off them, and wrote up their experiences on line somewhere where search engines can find them. Let’s hope this virtual diary post is therefore useful to others!

Firstly, high resolution pictures, because there aren’t any online that I could find and without these it’s very hard to figure out how the board is routed:

The overall dS3484 board, in its optional extra case

The processor, a PIC32MX795F512L, with a 2Mb flash from Microchip to its left

Above you can see the Ethernet PHY chip, the RS485 serial chip, and the 12v buck converter to 5v.

The board has very good build quality. Soldering and traces are clean, every input and output is buffered, and a very wide range of voltages is therefore tolerated. The Hongfa 16A relays are considerably better quality than the cheap Chinese 10A claimed relays normally in tinkerer boards and I think I’d trust them with 230V AC. I tried out the relays, the digital i/o both as input and output, and the analogue inputs. Analogue inputs looked very stable when fed a potentiometer, no noise, drift nor random walk, and the full 10-bit range was clearly present with equal resolution at the extreme low and high as in the middle (unlike ESP8266 for example). Ethernet came up and worked without issue. I plugged a cheap 12v AC adapter into it, found no issue. 5v output from the board measured at 5.1v, which is fine. I haven’t tested the RS485 port nor UARTs, but I intend to do so soon. The USB socket, incidentally, appears as a serial port to your computer. I don’t think you can use it for anything other than with the dScript IDE, which seems rather unfortunate.

All in all, I think the hardware great value for €75. This board is maybe 20% more expensive than the cheapest ethernet relay boards off Aliexpress, but it’s an absolute world of difference in build quality. I’d trust this to switch an immersion, which I don’t think a good idea at all with any of the typical relay HATs for the Raspberry Pi.

Regarding the software side of things, I didn’t get too much time to play with that this weekend – you’ll need to wait until next weekend for me to have a proper go off the proprietary programming language. On the one hand, this isn’t some dumb board with no locally programmable logic blindly obeying commands hitting its Ethernet port – it is quite programmable e.g. if five conditions are satisfied, connect to another computer and write some arbitrary payload to that socket, or accumulate statistics, analyse them and email a summary every day. On the other hand, its proprietary dScript programming language is a weird mix of features and capabilities, some big fat ones like the ability to send email, yet no time keeping better than a second unless you implement your own.

However I did write this little dScript program in the dScript IDE to test the board:

const STEPS 16
const DELAY 1000

int32 on_count
int32 off_count
int32 on_max
int32 off_max

thread main(const)
  int32 N
  off_max = STEPS
  off_count = 1

  threadstart Timer1
  threadsleep DELAY
  for N = 1 to STEPS - 1
    threadsleep DELAY
    off_max = N
    on_max = STEPS - N
    if on_count == 0 and off_count == 0 then
      on_count = 1
    endif
  next
endthread

thread Timer1(1)
  if on_count > 0 then
      on_count -= 1
      if on_count == 0 then
        IO1 = off
        off_count = off_max
        threadsuspend
      endif
  endif
  if off_count > 0 then
      off_count -= 1
      if off_count == 0 then
        IO1 = on
        on_count = on_max
        threadsuspend
      endif
  endif
endthread

Which yields this on a RGB LED I hooked up to digital i/o 1 which uses PWM to reduce the brightness of the LED from 100% to 6.25% in even steps over sixteen seconds:

The video makes it look far worse than it is to the human eye, where any PWM flicker isn’t noticeable until the dimmest setting, and even then, only from the side of the eye’s focal point. The PWM flicker is due to the 16 ms duty cycle, which is only 62Hz, barely any better than a cheap diode based LED AC bulb flickering at 50Hz. But it’s the best possible on a millisecond granularity timing system, which is the finest timer granularity dScript exposes. This is unfortunate as even though dScript is an interpreted language running on an 80Mhz CPU, it should be able to pulse an i/o at 50Khz in software if the board isn’t doing much else.

In case you were wondering, yes the PIC32MX has hardware PWM. However dScript doesn’t expose that, and when I asked Devantech support if it could, I was told that the PWM capable pins are not routed to digital i/o, which seems to me a missed opportunity. Again, that weird mix of features and capabilities at work. Incidentally, I also asked how much current the 5v outputs could supply as it isn’t documented anywhere, and I was told around 500 mA. Which is very useful to know.

In any case, timers do appear to reliably fire bang on 1 millisecond – the PWM, despite the video where the phone camera’s own refresh rate is colliding with the PWM refresh rate – appears to my eye absolutely regular. No stutter, though obviously this is not a loaded system.

The proprietary language dScript seems to be a reasonable attempt at a coroutine based BASIC-like embedded systems language. What the language calls ‘threads’ are actually coroutine event handlers, so you declare what event you are interested in e.g. timer elapse, TCP/IP input, board boot, i/o state change and so on, and you write code which will be called when that event occurs. Digital i/o appear to be non-blocking (instant), but analogue input read, serial port read, TCP/IP read and so on appear to suspend the coroutine’s execution until the blocking input completes, upon which execution is resumed. Most writes go into asynchronously flushed buffers and so don’t usually block. Whilst your coroutine is suspended, other coroutines may run. The scheduler is cooperative, so if any coroutine executes for too long, it blocks the execution of other coroutines, and events for a given input after the first event may get dropped as there is no buffering, as befits a hard realtime implementation which cannot allow unbounded dynamic memory allocation.

This coroutine based fixed-at-point-of-compile approach suits well deterministic programming, though it is unavoidably a bit awkward to write code in as a result (think WinRT programming, but minus any dynamic memory allocation). As there is no preemption, there are never races on shared state, which is good because all non-local state is globally visible like say in a single translation unit of C. As all possible memory allocations are known at compile time in the dScript IDE, memory is preallocated for volatile and non-volatile RAM and program bytecode. Strings are supported, but you cannot create new ones programmatically at runtime i.e. with runtime determined length – anywhere you format numbers into a string it preallocates string space for the maximum possible formatted value. There is no floating point support, which is to be expected for such a low end CPU which would lack hardware floating point, but there is what appears to be an optimised boolean expression evaluator which I assume is expanded out into a finite state machine rather than sequences of bytecode for the logic, so if-then-that type logic can be tersely and very efficiently encoded into a constant state table.

An unexpected feature of these Devantech dScript boards is that they can serve a user defined website of your choice on HTTP and moreover, said website can call arbitrary dScript via AJAX from Javascript. This lets you build web based UIs or reporting or summary dashboards for your particular setup, which is very nice. In fact, the whole system config and setup web UI for the board is written entirely in dScript, which shows what is possible if you are willing.

Anyway, next weekend I’m going to have a go at writing an actual piece of control software for my particular project in dScript. It’ll have a summary dashboard served as HTTP, so you can always see what state it is at and why. I may or may not also have it push state changes to Home Assistant, e.g. current light brightness, and if I get the time, add remote automation by Home Assistant of the project. I’ll no doubt report on my progress here!

#house




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)
16A
relays
Digital inputs
and outputs
Analogue
inputs
Serial
ports
CountersCPUFlash
storage
RAMTDP
(12v DC)
Other notes
dS1242€5924x VFC input or NPN output2x 10-bit1x TTL8x 32-bit trigger, 20 Hz input count80Mhz PIC32MX795F512H
(guessed)
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
(source)
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 https://www.antratek.com/, 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.

#house




Monday 30 August 2021: 20:49. It occurred to me that I haven’t posted an update on my P2P earnings #mintos in about six months, so I thought I would do so now:

MonthMintos annualised return for each monthMintos non-earning capitalMoncera annualised return for each month
December 202011.29%11.4%
January 2021 10.21%11.4%
February 202112.82%11.4%
March 2021 17.57%11.4%8.54%
April 2021 10.63%17.1%8.59%
May 2021 10.46%18.8%5.97%
June 2021 12.97%22.7%9.39%
July 2021 11.70%27.4%11.53%
August 2021 10.91%27.4%11.42%

That non-earning capital, to remind readers, is the money I had invested in Polish Capital Service which is currently under a covid restructured debt repayment plan and during which it isn’t paying out. So considering that this drags down the annualised return, the returns from Mintos on the earning capital have been very healthy indeed such that the typical annualised return has barely dropped over this time last year, and that is even as I have been drawing out about half of my Mintos total investment – as evidenced by the proportion of non-earning capital more than doubling as a relative share. This is mostly because I was lucky – last post on Mintos I mentioned that I was moving away from car loan giant Mogo (since renamed to Eleving Group) into DelphinGroup and IuteCredit. Around March DelphinGroup bought back all my loans and stopped issuing new ones on Mintos, so I decided to take a punt on investing in Creditstar who https://explorep2p.com/mintos-lender-ratings/ think fourth best on Mintos, despite their 6-7 rating by Mintos. I thus locked in a bunch of loans at 14-15% APR, and to date neither IuteCredit nor Creditstar have bought back their loans, so I’ve been doing rather a lot better than the typical 9% APR on new loans in Mintos last few months. Eleving Group/Mogo began buying back my high APR loans in dribs and drabs over several months, and I think I became completely clear of them in July through doing absolutely nothing, which suits me fine as their new loans pay peanuts. On Mintos, I am now about 41% IuteCredit, 39% Creditstar and 24% ESTO (ranked 11th by explorep2p, yet rated 8 by Mintos), albeit on less than half the total investment when compared to January.

You will notice a new column up there for Moncera. This is a fairly new P2P investment site exclusively for Placet Group, who are rated the best quality P2P lender by explorep2p, but because they pay such paltry APRs on Mintos I’ve never invested with them. However the exact same loans on Moncera pay considerably better than on Mintos, and indeed were paying better than anything somewhat safe on Mintos (> 10% APR), so from March onwards I moved over half of all my investment to Moncera. Moncera appears very good if you don’t mind the fact that it’s a single loan originator and that if it did ever go bust you’d have no one to fight your battles for you, whereas Mintos have at least proved that they’ll go to bat with their own solicitors to recover at least some of your money from loan originators who try to shirk their obligations.

All in all though, all my P2P investments shall be getting wound down during 2022 as I’ll need every penny that I can lay my hand upon to build my house. The goal of all this P2P investing was simply to preserve some value from inflation on a cash pile, and I never risked more than would earn about 1% per annum on the total cash amount. That cash pile mostly just got sunk into buying a site, the remainder will be paying professional fees to reach planning permission and then maybe if there is enough left it might just about pay for site clearing and groundworks. All the remainder will come from a mortgage, and as that won’t be enough either, several upcoming years of future income which means I’ll be saving absolutely nothing. So, to put it plainly, the days of there being any cash pile to lose value upon from inflation have already begun to end.

Once the P2P investments start to make up a fifth of all my remaining cash I’ll stop their automatic reinvestment and let them cash themselves out slowly. I’ve noticed that they buy back about one third of your original investment every six months just from churn or whatever, so that’s about one fifteenth of your total cash pile every six months. If I need it to go quicker I can always sell the loans on the secondary market, though that comes with a 0.9% exit fee (Mintos) or 0.5% exit fee (Moncera).

I may or may not do another post on P2P investing in the future. I hope you all enjoyed the series of posts and it gave you some new investment ideas.

#mintos #p2p-lending




Monday 2 August 2021: 00:50. The last few months have felt like an awful blur. Some of it is the birth of my third child, Julia, with all the impacts to one’s routines a newborn brings with them. Some of it was gearing up to bring everyone to England in the middle of a pandemic for my brother in law’s wedding without either catching covid, despite that England was riddled with it, or getting trapped by borders closing – in the end, we rented a campervan so we’d never need enter indoors anywhere, and took ferries which brought us back to Ireland via Northern Ireland, all of which was most stressful and very draining, but we got it done at the start of July, and it all worked out well in the end (equally, I would not wish to repeat it ever again). However no doubt the rest of it is that now Julia is born and both her and mother are healthy, I’ve started the ball rolling on buying a site, and building a house on it!

The Site

So far, buying our site has not gone well! Just the buying of the site alone has been a plague of issues and stress. The site is a serviced site within a partially built housing estate deep in rural Cork which is the result of the global financial collapse in 2008. The story begins with a Joseph O’Callaghan who received planning permission to build forty-three houses as an estate in year 2000. As far as I can tell, he was not a professional developer, but rather a local businessman and farmer, and I’m guessing he did not intend to build all the houses himself. They appear to have built the roads, installed services and street lights etc, or possibly contracted in builders to do it, and the estate got itself named by start of 2006. In any case, starting from June 2005 onwards you start seeing individual site planning permissions land at a fairly rapid clip: in order, numbers 1, 7, 12, 11, 13, 20 & 21, 3, 2, 15, 6, 5, 31 & 32, 19, 35-36-37-38, 24, 28 & 29, 30, 16. And then bang!, no more planning applications for new houses on the estate between July 2007 and February 2015!

What happened was that building of the later granted sites never began before the global financial collapse of 2008. Looking through the planning applications and comparing it to the property sales register (both are public access on the web), a minority were individuals who later occupied the house they built, and a majority were from somebody involved in construction who were looking for somewhere to invest their spare cash, with the idea of building a few houses on the side of their main business and flipping them for a profit. As much as many private individuals got badly caught out in the housing price collapse of 2008, those in construction who were dipping their toe into becoming small scale builders of a few houses on the side got a lot more badly burned – a feature of this housing estate is if you don’t start building within thirty months of getting planning permission, you have to pay a fine per site of €1,000 per month! So after 2008, not only were they in deep negative equity, they were also in a cash flow crunch. Hence no planning applications for new houses for eight years!

This of course happened to lots and lots of people who either bought housing or sites just before the housing market collapsed in Ireland. And it took a good decade to sort out, what with everybody owing everybody else vast sums of money, and nobody wanting to act on any of it because that would realise their losses. At the time, I remember feeling I was losing out badly due to my then poverty, as I was still a poor student. I look back now and feel so very sorry for all those unfortunate people, it literally ruined a whole generation.

In any case, the people who own our site appear to have decided to offload their sites some time in late 2019. They went up on the market mid 2020 at an asking price of €85k each, which I reckon was about a 50% haircut over what had been paid for them. Given how far away this village is from anywhere at all with jobs, and that even a site within the Cork city boundary could be found for that kind of money, the sites did not attract much interest.

Earlier this year, I had been bidding on two sites in the North Cork village where I currently live, Dromahane, but I had bailed out when the price went to €85k as I just didn’t think either site worth that (one was very small, the other had no access to the public sewer and was too small to easily fit a septic tank). So I knew where my price limit was roughly at, and where the market was roughly at, for sites near places with jobs. Also, Megan had begun to see that getting a site near Mallow was going to be expensive, and there would likely have to be considerable compromises in terms of shape, size, or budget. So she became a bit more open to moving further away than before. In March I took her to look at sites for sale in this partially built housing estate in this rural village far away, and she agreed that the sites were much better quality, the amenities were great, there is a train station next door, indeed everything bar macro location was great (though location within the village itself couldn’t be better). Because of that poor location, I put in an offer for two of the sites purchase subject to planning, and my offer was accepted in principle end of March.

Cue then three sets of solicitors (mine, the sellers’, the estate’s) taking – to date, it’s still ongoing – four months to come up with a contract! Obviously the sellers and the estate developers wanted to push through the conditions as was in 2007 to me, with the rather important bit being the €1,000 per site per month fine if I don’t complete a house within thirty months. That was a showstopper for me, and eventually after much haggling the other sides relented. Also, since 2019 the EU has imposed much tighter regulations for building new houses, specifically you now need an energy consultant in addition to an architect and typically a structural engineer, and lead times to reach planning permission submission are now far longer than they were before 2019. So all the conditions originating from year 2007 involving what must be accomplished within X months from whatever needed to be doubled or trebled because they were no longer realistic. Hence more shuttling backwards and forwards between the three sets of solicitors.

Supposedly, the final contract will be ready for signing by me in ten days or so i.e. mid August. It’ll then need signing by the other sides, and we shall finally be off to the races after a mere five months. Yay.

The House

In terms of what to build and how to build it, our current intent is an unusually tall bungalow measuring approximately 18 metres long x 10 metres wide x 9 metres high with a 40 degree (i.e. steeply) sloped roof. If that sounds like a two storey height, you would be right – the idea is a bungalow but with Victorian height internal walls plus a loft conversion with added height in the loft, so basically the ceiling of the ground floor and floor of the loft part is a bit lower than half up the total height of the house (3.6m internal walls downstairs, 4.5m floor to peak of internal roof upstairs) i.e. instead of dividing a two storey height house into two floors and an attic, we’ll be dividing it into one floor and an attic. The hope is that it will be passive house certified, meaning that total energy consumption must be measured as below 60 kWh per metre squared per year which essentially means the house heats and cools itself using ambient heat i.e. no heating system needed (though we shall be fitting a single radiator in order to meet Irish building regulations which require there to be a heating system in the house, but also in case there is only one occupant, as the heat emitted by the human occupants makes up a substantial portion of the total heating of the house). Total internal living space is estimated to be around 260 m2, with the six metre wide ten metre long main living room running floor to roof in height i.e. the full eight metres high, which ought to be quite impressive to walk into and be in as it’s effectively like being inside a church, which is the effect we are intending.

We have commissioned as our architect Rebel Design Studio who specialise in building photorealistic virtual reality models of the proposed design, which until very recently was the preserve of high end architecture for really big developments such as shopping centres or large office complexes. We’ll be at the state of the art here, combining Unreal Engine with Twinmotion to produce a three dimensional render of the proposed design. Given my past UE4 experience during the DTS contract, I’ll then take that model and convert it for the Oculus Quest 2 VR headset, and then we’ll be able to walk around our future house to see how it feels. The Oculus Quest tracks you physically walking around exactly evenly, so if you walk one metre with the headset on, you’ll walk one metre inside the VR model. Obviously I’ll post a video flythrough here when we have them, but I suspect it’ll not be a patch on wearing a proper VR headset. The only issue will be finding a flat safe 18 x 10 metre space to walk around in with the headset on, and that assumes we don’t try walking outside the VR house!

Other unusual features of the house

Earth tube

Apart from it basically being a church which is unusual, there are a few other novel features intended which may get deleted or refined as expert advice comes in. The first is that my highly inexpert calculations currently reckon an earth tube worth the cost benefit, which would be highly unusual for a climate as mild as Ireland’s. Earth tubes are basically a 0.2m diameter pipe under the ground for 40 or 60 metres, and the ground is typically 10 - 12 C throughout the year. The ventilation unit sucks incoming air through the earth tube, so in winter this would warm the air, and in summer it would cool the air, before it enters the house. Passive houses are extremely well insulated and so airtight that without a ventilation unit you will suffocate (indeed because the concept comes from Germany, it was designed around the Central European climate and the insulation is actually overkill for the mild Irish climate, however because Passive House is a standard, it’s cheaper to meet the PH standard than do something specific for Ireland). Because the PH standard requires a highly efficient heat exchanging ventilation unit which transfers the heat from expelled air into incoming fresh air, earth tubes don’t benefit a passive house much in winter. However, in summer they provide substantial cooling, and the hotter it is outside, the better the cost benefit. Generally earth tubes only make cost benefit between Southern Central Europe and North Africa, and not in Ireland where the average summer temperature is about 17C (across day and night) which has insufficient differential to the ground temperature to provide worthwhile cooling. However in our case, I reckon an earth tube would give about negative 1kW for the house by my calculations even with all the heat pouring in all the windows. That means we can increase the amount of glazing quite a bit i.e. we spend extra money on an earth tube so we can spend more money again on more glazing and it shouldn’t overheat. This clearly doesn’t meet cost benefit by definition, but let me explain my thinking on this some more.

Almost all houses built in Ireland since the 2019 EU NZEB regulations came in have a heat pump to meet the 20% renewable energy requirement, so not having a heat pump I can already see will be controversial. If a heat pump costs €8k, because a Passive House uses so little energy, a heat pump at 400% efficiency in winter has a payback time of nineteen years. Alas a heat pump likely needs replacing every fifteen years, and has expensive maintenance (e.g. recharging every few years its heat exchange gas, which is patented and hideously expensive), so for very low energy consumption it just doesn’t have cost benefit like it would if we used more energy. To give an idea of how close this cost benefit is, if my planned house simply dumped shower waste water as-is into drainage, the energy consumption would become high enough that a heat pump becomes worth the cost benefit. But because I’ll be fitting a heat exchanger to all the shower and bath wastewater to reclaim the heat before the water is dumped to drainage, that sufficiently reduces total house energy consumption that a heat pump is no longer worth it. That waste water heat exchanger costs about €1,200, and the maths say it has one of the best cost benefits of anything else I’ve chosen – much better than solar panels, which was a surprise.

An earth tube is pretty similarly priced, at about €6k, it just needs cleaning with a brush every few years, and a new filter every year, and otherwise ought to last the building’s lifetime whilst consuming almost no electricity at all. It does almost nothing for reducing your heating costs, because the heat exchanger in the ventilation is already so efficient. But it should completely eliminate overheating in summer, and indeed make possible more glazing than would otherwise be possible. So it is more an insurance, or a fixed asset part of the glazing expenditure, than having anything to do with running costs, and therefore should not be treated as cost-benefit, but rather as ‘will spending this money get me features that I want?’ i.e. more windows.

Thermal store

Most higher end houses have a dedicated hot water tank which is heated by a heat exchanger from the home central heating i.e. the boiler pumps hot water through the radiators, and effectively there is another radiator inside your hot water tank which then heats your hot water. Obviously there is usually a valve bypass so your boiler can heat the single radiator inside your hot water tank, and not pump through the radiators in your house.

A surprising outcome from the maths I ran is that for this specific house, it makes a lot of sense to invert that design. Instead of a tank with domestic hot water heated by your radiator circuit, you make your tank contents the same as your radiator circuit, and place your domestic hot water tank inside your ‘radiator tank’. This is called a ‘thermal store’ and it basically inverts the traditional relationship between domestic hot water and your radiator circuit. Thermal stores are typical in larger buildings like office blocks. They don’t usually have cost benefit for a building as small as a house.

The reason that cost benefit works for our house is that thermal stores have weird maths. Because heat loss is a proportion of surface area, but heat capacity is a function of volume, the bigger you make your thermal store tank, the more efficient it gets. It actually has cost benefit to fit a 5,000 litre thermal store tank to this house, at least according to my crude calculations. 5,000 litres is an enormous store of heat, about 230 kWh of space heating if heated to 60C. Given that our passive house might require at worst 1.6 kWh of heating in winter, that is a potential six days of worst case space heating in a single tank, so in normal times you might have two weeks of heating in there. The reason why this matters is because the Irish weather in Spring and Autumn swings between quite sunny and overcast, typically with up to a week of overcast between the sunny days. The idea is that on that sunny day, the solar panels heat the thermal store, and then that thermal store delivers any space heating and domestic hot water needed during the overcast days, and if it is unusually overcast for a long period of time, we can use cheap night time electricity at €0.10/kWh to keep the top of the thermal store hot. If you run out the numbers, this has the second highest cost benefit after the waste water heat recovery because for eight months of the year, you shouldn’t need any electricity for space heating nor domestic hot water at all, on average. This was also quite surprising when the numbers fell out this way – passive houses generate weird numbers, because they are so insulated.

Thermal stores have other advantages too. Have you noticed how your hot water tap has low flow and your cold tap has high flow? This is due to pressure, a hot water tank doesn’t deliver much pressure compared to mains water (at least 1.0 bar in Ireland). However a thermal store feeds mains cold water directly into the inner tank within the thermal store tank. Therefore, hot water has identical pressure to cold water. This might seem unimportant, but consider every time you’ve waited for your shower to warm up, or the sink to get warm when washing your hands – at 1.0 bar, that hot water tap gets hot very quickly. That, in turn, means your shower gets instantly hot, no need to wait, and that in turn reduces waste but also improves quality of life, a few minutes saved every day adds up.

Also, your typical hot water tank fed shower might deliver five litres/minute, due to the low pressure. With a thermal store, thanks to the 1.0 bar pressure, my maths says that same shower would deliver eighteen litres/minute, which is far nicer. And thanks to the waste water heat exchanger, most of that shower water will end up heating shower water, so no need to feel guilty about dowsing oneself in eighteen litres of shower per minute. Obviously I’ve thus specified large rainfall type showers for all three showers, because with eighteen litres/minute you really will get a very good shower indeed.

Home automation

‘Smart’ homes are all the rage for high end housing right now. But I’ll be skipping multiple generations ahead by making the entire house Home Assistant based from the very beginning. Home Assistant is an open source enthusiast home automation system, so you can program things like ‘if the weather forecast says there will be no sunny days for the next week, and the thermal store has 10% hot water remaining, turn on the immersion from 12am onwards using cheap night time electricity until the thermal store has 15% hot water remaining’. Or ‘illuminate the lights around Clara to no more than 75%, but illuminate the lights around Niall to 100%’ and that light illumination would follow you around the house, including adjusting itself appropriately for when you’re stumbling towards the toilet half asleep in the middle of the night. If none of that sounds fancy enough to be worth the trouble, you can also program it things like ‘if a cat enters my property, send the robot lawnmower out to follow it to scare it away’ and ‘if a human enters my property and that human is a family member, don’t send an intrusion alert to Niall’s phone’.

This all might sound impossible to some reading, but it’s all completely possible today right now with Home Assistant. It just requires a reasonably powerful always on computer, which I already have in my current rented house. Because it’s enthusiast, it’s multiple generations beyond all but the very most expensive of commercial smart home solutions. Yes I’ll have to rig it all together myself. Yes it’ll take me years to get it all done. But I’ll have a smart home system worth €40k or so for pocket money, albeit plus quite a lot of my precious free time. And because it’ll all be hand written and hand wired, it won’t be needing a constant internet connection to work, unlike all of the commercial smart home systems as far as I can tell.

To power all this home automation, I have been careful to only choose components (e.g. the home ventilation unit) with great compatibility with Home Assistant, and I’ll be running a 48v DC circuit around the house, plus feeding the 48v into the ethernet all over the house. I expect there shall be a lot of Power over Ethernet devices, as I am not at all keen on Wifi, Zigbee nor Z-Wave IoT devices where a hard wired alternative is feasible (which is almost always). I expect the 48v DC circuit to be capable of 50 A, which is 2.4 kW of power which might seem extreme. However, not only will all the IoT will run off that line, but so will most of the lighting which I expect to be LED strips of various kinds also intelligently controlled by Home Assistant. I’m actually currently typing this underneath some hand made experimental cove lighting, and I’m rather liking it for what it cost me (mostly my precious free time, the parts were well under €100).

Projected cost

This is of course that elephant in the corner. Passive house does not come cheap. Victorian high ceilings do not come cheap. Lots of glazing does not come cheap. Yes, all this is going to cost me.

I’m no quantity surveyor, but I have compiled a list of all the components and materials I think we shall need and put my best guess as to prices on all of them (this has consumed a very great deal of my precious free time in the past few months). I currently estimate that this house plus a separate outhouse will cost €452,000 excluding professional service fees and contractor profit margin. Assuming those at 10%, this house is expected to cost around €500,000.

Now that is an awful lot of money. I am fortunate enough that right now I am earning quite well, but still, that is an awful lot of money. To put it into perspective, in the estate where we shall be building this, no house there has ever sold for more than €290,000. So if I spend €500,000, I am straight away €200,000 in negative equity. That’s just nuts if you think about it.

Still though, all this isn’t really about resale value. It’s about ‘getting what you want and how much it’ll cost you’ value. Forever homes have atypical cost benefit dynamics, because you’ll be borrowing money from the bank to build something you’ll enjoy over hopefully decades so you’re not judging expenditure against present day valuations, but against probable valuations in twenty years or so. Given the long term and ongoing decline in the interest rate as ever more people retire and ever fewer productive workers support the retired, the volatility of fixed asset pricing can only increase – and probably very considerably so. So I expect still further huge increases in valuation of real estate, but I also expect much more frequent boom-bust cycles in real estate. Because as the interest rate gets ever closer to zero, the system will only increase to destabilise unless politicians actually do something about it. Assuming near zero likelihood of politicians actually doing anything substantial to keep house prices reasonable, I think the chances are very good that in twenty years my property will be worth a million or so. And my kids shall remain living with me forever because it’ll be a much better place to live than elsewhere, but also because there is near zero chance they’ll ever be able to afford to own their own house. So my generation shall return to the historical norm outside this past half century, which is that your kids have their families right next to where you raised them, and you’ll likely get roped into grandchild care.

I’ve accounted for this in the design – it is not adverse to multiple families being reared in the property, which seems a quite likely future I reckon, especially as comparing recent empirical measurements to the 1972 predictions from The Limits to Growth appear to be close to bang on track for a predicted civilisation peak around 2040, and thereafter a steep decline in almost all metrics, including food production. As food for thought, in 2040 Clara shall be 26, Henry shall be 23, and Julia shall be 19. I will be 62, and Megan will be 56. There is even a non-zero chance that my father may just about be still alive, aged 94! I hope to be 80% food self sufficient by then, though without industrial goods that isn’t sustainable for more than a decade or two e.g. solar panels may last thirty years, but solar inverters need replacing every fifteen years. In any case, I am fairly confident that we shall have done all that is possible to give the best possible platform for our children to do as best as will be possible in a declining civilisation, and that me and Megan shall have as pleasant as possible a dotage.

Given the recent massive flooding in Europe and China, I’ve also made sure that the house is raised 0.5 metres above all surrounding land as climate change will almost certainly cause a major flood event where my house shall be during the next few decades, and a bit like with when bears are chasing you, you don’t need to be the highest just slightly higher than everything else when it comes to water.

However in the end all you can do is design around known knows and known unknowns. It’s the unknown unknowns which will catch you out.

#house




Saturday 29 May 2021: 22:44. It is almost June, so here is the latest update to my annual comparison of storage bytes per inflation adjusted dollar for magnetic hard drives, flash SSDs, and Intel Optane XPoint devices (you can find all the past posts here), which I have done every June since 2012:

Raw data: http://www.nedprod.com/studystuff/SSDsVsHardDrives.xlsx

This is an unusual year, hard drives are about one third more expensive this year than they were last year (I am very thankful I replaced earlier this year all my hard drives with 3x 16 Tb Seagate drives, I clearly timed the market beautifully). Yet, SSDs are one third cheaper than last year, which is an unusually good annual improvement which appears to have undone last summer’s SSD price increases. Meanwhile Optane X-Point is completely flat – not just nearly flat, but absolutely identical dollar prices to this time last year, only the effect of inflation very slightly improved their bytes per inflation adjusted dollar. Clearly Intel feel no need to bring NV-RAM to the mass market until competing products launch and force them to compete on price , which hopefully will be soon.

So why have hard drive prices increased? Everybody is blaming Chia mining which is a cryptocurrency based on pointlessly wrecking hard drives into landfill rather than pointlessly converting electricity into heat like Bitcoin. The Chia network is currently consuming 1.2 Exabyte at the time of writing, which might sound a lot, but it’s only 75,000 16Tb hard drives, which is a rounding error on annual production. So I suspect the true cause is the same as why car production has stalled, as has CPU production and graphics card production, it’s due to the global shortage of silicon chip production in general. And no doubt somewhat related is the post-pandemic steep rises in the price of copper and rare earths, and just that demand in general is vastly exceeding supply.

I expect this time next year hard drive prices will have dropped back onto their long term trend line, and SSD prices perhaps will be flat. We shall see!

#ssdsvsharddrives




Monday 8 March 2021: 20:44. I had a pretty bad week last week at work. My main development workstation had, on the preceding Friday, crashed taking my development VMs with them, so I spent the weekend before last reinstalling Ubuntu 20.04 with ZFS-on-Root (my standard Linux setup for five years now!), moving the work codebase onto that shared with Windows over Samba, with the intent of building for Linux within the VM, and building for Windows from the Samba share. This was a big divergence from my previous setup of Windows Subsystem for Linux v1 doing the builds for both Linux and Windows, and then I’d run the Linux executables over a Samba share. There is nothing wrong with my former setup for smaller codebases, but as the work codebase approaches 150k LOC, WSL v1 based Linux builds are getting unwieldy slow. And WSL v2 is the same as a Linux VM, except the file system is shared by 9p rather than Samba, and 9p is very considerably slower than Samba, so you’re much better off configuring your own Linux VM and Samba installation and tuning the snot out of Samba.

Anyway, all of last week my developer workstation kept locking up, losing me work in progress. I tried relocating the NVMe SSD (a Samsung 970 Pro) into a new M.2 socket, and since then it appears to be reliable again. But that’s water under the bridge, what I’m here to talk about now is how I fixed Visual Studio 2019 not building reliably over a Samba share, because absolutely nobody else seemed to find a solution to this oft reported problem (well apart from this guy here who found a workaround to a related but different problem which has the same manifestation as mine).

Firstly, I am not building into the Samba share. I create a build directory on Windows, and tell cmake to populate that Windows build directory using a git worktree located on a mapped network drive M:\ which is the Samba share of the git worktree in the Linux VM \\kate-linux. As the build never writes into the source worktree, Samba is only being used here for reads only, and so thanks to opportunistic locking (oplocks), Windows aggressively caches the source tree in Windows and build performance is pretty close to native speed.

Except, it’s not quite reliable. 99.9% of the time it works fine. But occasionally MSVC doesn’t find some header file, or Visual Studio refuses to save a file, and if you look in the directory it is creating lots of orphaned temporary files from the failed saves. The problem is much worse if you use --parallel with cmake --build . --config Debug where MSVC will fail to find lots of header files, sufficiently so that you don’t get a usable build. Initially I thought this was purely a MSVC/Visual Studio problem, as it only ever appeared there, not helped by all the google searches reporting the same problem and almost all also mentioned MSVC/Visual Studio. But I also noticed that occasionally executing git from Windows where the git repo was on the mapped network drive would fail too with messages such as:

fatal: update_ref failed for ref 'HEAD': cannot lock ref 'HEAD': unable to create lock file non-directory in the way

… and other messages suggesting that the network share was being racy with respect to changes on the network share.

My initial thought was that Samba must be misconfigured, even though it was pretty much with default config, and Ubuntu 20.04’s Samba is v4.11.6 which to my best knowledge, has no known major bugs and its default config is pretty optimal for performance, unlike earlier versions before Samba v4. I spent all last week when I was waiting on Linux build trial and error A-B testing various network and Samba configurations, alas to no avail.

This weekend passed, and today Monday morning I had a bit of a brainwave: What if Samba is absolutely fine, and it is Windows 10 which is the cause?

That led me to Microsoft’s documentation page about SMB2 Redirector Caches which documents three registry settings to fiddle with. It turns out that setting these parameters in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Lanmanworkstation\Parameters fixes all my MSVC failed-to-find-file, Visual Studio 2019 failed-save-edited-file, and git failed-to-checkout-branch problems:

  1. DirectoryCacheLifetime = (DWORD) 0
  2. FileNotFoundCacheLifetime = (DWORD) 0
  3. FileInfoCacheLifetime = (DWORD) 0

After you have set these using regedit, Run services.msc, find the Workstation service and restart it. To verify it’s working, open powershell with Administrator privileges and do Get-SmbClientConfiguration:

ConnectionCountPerRssNetworkInterface : 4
DirectoryCacheEntriesMax              : 16
DirectoryCacheEntrySizeMax            : 65536
DirectoryCacheLifetime                : 0
DormantFileLimit                      : 1023
EnableBandwidthThrottling             : True
EnableByteRangeLockingOnReadOnlyFiles : True
EnableInsecureGuestLogons             : False
EnableLargeMtu                        : True
EnableLoadBalanceScaleOut             : True
EnableMultiChannel                    : True
EnableSecuritySignature               : True
ExtendedSessionTimeout                : 1000
FileInfoCacheEntriesMax               : 64
FileInfoCacheLifetime                 : 0
FileNotFoundCacheEntriesMax           : 128
FileNotFoundCacheLifetime             : 0
KeepConn                              : 600
MaxCmds                               : 50
MaximumConnectionCountPerServer       : 32
OplocksDisabled                       : False
RequireSecuritySignature              : False
SessionTimeout                        : 60
UseOpportunisticLocking               : True
WindowSizeThreshold                   : 8

Note the zero values for the parameters we forced to zero, but large MTUs remain on, oplocks are on, and multichannel is on.

SMB Multichannel is probably the only major Samba performance enhancing feature not enabled by default in Samba v4. This is because it was buggy until recently, but now it’s working very well. SMB Multichannel lets file transfers multiplex over multiple TCP connections, so just like with Download Accelerators on the internet, you can multiply a per-TCP-connection maximum several fold over multiple connections, thus greatly increasing transfer rates. This isn’t particularly important for many small files like during a C++ compile run, but if you have multiple threads all accessing a single Samba share, with SMB Multichannel those threads actually see some concurrency whereas without SMB Multichannel, they all get funnelled through a single TCP connection with a global mutex. So, for a parallel build like what Visual Studio now does by default, SMB Multichannel is a big gain.

You can see if your Hyper-VM Linux and your Windows installation are already employing SMB Multichannel using this command in an Administrator privileged PowerShell:

Get-SmbMultichannelConnection -IncludeNotSelected

Server Name Selected Client IP     Server IP       Client Interface Index Server Interface Index Client RSS Capable Client RDMA Capable
----------- -------- ---------     ---------       ---------------------- ---------------------- ------------------ -------------------
kate-linux  False    192.168.137.1 192.168.137.235 7                      2                      False              False
kate-linux  False    192.168.2.172 192.168.137.234 11                     1                      False              False
kate-linux  False    192.168.2.172 192.168.137.234 11                     1                      False              False
kate-linux  False    192.168.137.1 192.168.137.234 7                      1                      False              False
kate-linux  True     192.168.137.1 192.168.137.234 7                      1                      True               False
kate-linux  False    192.168.2.172 192.168.137.235 11                     2                      False              False

If it prints nothing, SMB Multichannel is NOT being employed.

If your Samba is after v4.13, it should autodetect when your network setup is RSS capable on its own. If both sides can do RSS, enabling SMB multichannel is as simple as adding this into your smb.conf:

[global]

server min protocol = SMB3
server multi channel support = yes

Note you need to reboot your Linux VM and then your host Windows machine before this takes effect.

If your Samba is before v4.13, you will need to either force RSS on (ideal as it can parallelise according to CPUs in your machine) or assign more than one network adapter to both your VM and your host on the Hyper-VM bridge (not ideal, as max concurrency is the number of multiple NIC pairs between Linux and Windows). Here is how you force Samba to advertise support for RSS and RDMA:

interfaces = "192.168.137.234;if_index=1,capability=RSS,capability=RDMA,speed=10000000000"

Obviously, you will need a static IP for your Linux VM for this to work, and you need to enable RSS in the virtual 10Gb NIC and on the Hyper-VM bridge you are using.

I left RDMA enabled in there too, though it only makes sense on real hardware with a sufficiently capable real NIC on a real server. Obviously if you do have such capable hardware, you can sustain 10Gb/sec on a 100Gbit link with 256Kb per i/o @ QD8, or 2Gb/sec on a 100Gbit link with 4Kb per i/o @ QD200. Over a software emulated switch and NIC, the SMB Multichannel only mainly increases concurrency for both host and VM, helping ameliorate the VM<=>Host latency.

Finally, the only other settings which Samba v4 doesn’t currently enable which might help are:

socket options = TCP_NODELAY IPTOS_LOWDELAY
use sendfile = yes

TCP_NODELAY is already on by default in Samba v4, but IPTOS_LOWDELAY is not. This might improve performance a bit given that now Windows does no caching of metadata whatsoever given the registry changes above. And use of kernel sendfile() to zero copy transmit files is off by default, for some reason, so turning it on might reduce CPU cache loading a little.

Hopefully I helped other people now reading figure out the solution to what has been a very frustrating week for me in getting Visual Studio/MSVC to reliably build a Linux Samba share supplied git worktree.

#samba




Sunday 21 February 2021: 00:48. We currently live in a former council house near Mallow, Cork which suffers rather from damp and mould, though certainly not as bad as in many Irish houses, especially ones in the humid south. This gives us all constant coughs, plus our sinuses are always congested, and we often don’t sleep as well as we might because we wake up early due to being unable to breathe due to being all bunged up. I have a dehumidifier which is excellent at drying out a room sufficient that one sleeps very well, but it is (a) noisy (b) expensive on electricity to run. So I’ve been looking for something which could clean out some of the crap which gets into the air, is quiet enough it can run 247, is cheap enough that I can deploy it throughout the house permanently, and at least reduces the severity of what ails us from this house.

After a bit of research, I eventually settled on the Xiaomi Air Purifier 3C for €90 delivered within the EU from Aliexpress, buying one for every room in the house. These are the cheapest edition of the third generation of Xiaomi’s very popular air purifier range widely used in the big cities of China, India and Poland to reduce the fine particulate air pollution inside your home to less toxic levels (for every 10 μg/m3 increase of PM2.5 in your air, there is a +36% increase in lung cancer, and 7.5% of all heart attacks are due to PM2.5). My main attraction to them was that they can be controlled over wifi without a cloud connection (or indeed any access to any other network) by python-miio, so I can script individual behaviours for each such as when to go fast (daytime), and when to go slow (night time). Here’s my kitchen 3C in action:

They’re a very simple design, particularly the low end 3C model which has almost no onboard intelligence, unlike the more expensive models (one doesn’t need onboard intelligence if one is scripting them). They consist of a plastic base, a replaceable filter which fits into it, a quiet and high efficiency variable RPM AC turbine fan, a LED display, and a very low end ARM CPU with 2.4Ghz 11n Wifi and Bluetooth (the CPU is so low end that ping times are in the 400-700ms range, and REST API calls take 1.5 seconds or so). The turbine fan will spin at any RPM you choose between 300 and 2200, in 10 RPM increments. Finally, there is a laser-based PM2.5 sensor, but on this cheapest model no temperature nor humidity sensors.

As you can see below, my 3C came with the grey filter, which is claimed to meet the EN 1822 H13 (HEPA) standard specification removing at least 99.95% of all particulates equal or exceeding 0.3 microns in size (i.e. PM0.3). Note that anything less than 0.3 microns will get filtered by almost any kind of filter, because smaller particles bounce around a lot and get trapped by just about any density of fibre – therefore, these purifiers readily scrub the air of covid-19 and most other viruses too. Inside the wood fibre HEPA filter there is an additional activated carbon filter, which might soak up some odours and Volatile Organic Compounds (VOCs).

Despite this model’s simplicity, no other air purifier comes remotely close to the feature set for €90 delivered. In fact, you’d probably need to multiply by six if you want a well known brand such as Blueair with a similar feature set. Obviously, nobody is expecting that a Blueair model for €550 isn’t going to beat one of these for €90, but I’m fairly sure that six of these would handily beat a single Blueair, and do it quieter with cheaper replaceables, even if the Xiaomi filter isn’t as good as it claims.

Of course, by far the most important part of any air purifier is the filter itself, partly because it determines whether the device will be of any use or not, but also because they tend to be the expensive consumable. As with all things Chinese, there are a lot of clones of Xiaomi filters, but I believe I screened those out. Incidentally, I discovered on a chinese forum actual numbers for the claims by Xiaomi for their different filters, I don’t believe these are easily findable in English, so I’m going to list them here for your (and my later) convenience:

TypeModel EfficiencyColourRFIDDevice supportPrice on Aliexpress delivered to EU
EPA Economical M2R-FLPEN 1822 E12 (99.5%) BlueYes2/2C/2H/2S/Pro/3C/3H€31
EPA Anti-bacterial MCR-FLGEN 1822 E12 (99.5%) Pink PurpleYes2/2C/2H/2S/Pro/3C/3H€33
EPA Anti-formaldehydeM1R-FLPEN 1822 E12 (99.5%) GreenYes2/2C/2H/2S/Pro/3C/3H€36
HEPA M8R-FLHEN 1822 H13 (99.95%)GreyYes2/2C/2H/2S/Pro/3C/3HUnavailable

Each filter has a RFID chip which tracks how many hours it has been used for, and you will be pestered to replace it after about six months of continuous usage. The EPA grade filters are, with some difficulty to find at that price, available for as little as €31 each delivered within the EU. I could not find the HEPA filters for sale, though because they are just new on the market, you can barely buy them in China either yet, so that situation may improve within six months. Assuming they are at least €45, that means they were half the cost of buying the whole purifier!

As the air in Ireland is extremely clean from a PM2.5 perspective, auto mode based on the sensor reading isn’t useful here. That afflicts a high end brand such as Blueair just as much as this Xiaomi unit. Therefore you need to manually override them to run faster all the time in order to clean the air of mould spores, and that’s where the scriptability over wifi comes in, because I don’t really want to have to manually go around the house adjusting these manually. Here is the script I wrote to control them, you can obtain the device token using the instructions from Home Assistant (I set up a separate WiFi SSID on a VLAN, used the Xiaomi Home app to register the devices, then used the Xiaomi Cloud Tokens Extractor to get the tokens, then closed off all access between the VLAN and any other network including the internet. This script connects into the VLAN using a source IP spoofing NAT).

#!/usr/bin/python3

from miio import airpurifier_miot
from miio.exceptions import DeviceException
import time

class Purifier:
  def __init__(self, ip, token, name):
    self.ip = ip
    self.__token = token
    self.name = name
    self.__inst = None
    self.available = False
  def update(self):
    try:
      if self.__inst is None:
        self.__inst = airpurifier_miot.AirPurifierMB4(self.ip, self.__token)
        self.__inst.set_buzzer(False)
      status = self.__inst.status()
    except (airpurifier_miot.AirPurifierMiotException, DeviceException) as e:
      print("Failed to connect to", self.ip, "(" + self.name + ") due to", repr(e))
      self.available = False
      return
    self.available = True
    self.mode = status.mode
    self.powered_on = 'on' in status.power
    self.air_ppm = 0 if status.aqi is None else status.aqi
    self.led_brightness = int(status.led_brightness_level)
    self.current_rpm = int(status.motor_speed)
    self.filter_hours_used = int(status.filter_hours_used)
    self.filter_life_remaining = int(status.filter_life_remaining)
  def __repr__(self):
    ret = 'Purifier(%s) available=%d' % (self.name, self.available)
    if self.available:
      ret+= ' powered_on=%d air_ppm=%d led_brightness=%d current_rpm=%d filter_hours_used=%d filter_life_remaining=%d%%' % (self.powered_on, self.air_ppm, self.led_brightness, self.current_rpm, self.filter_hours_used, self.filter_life_remaining)
    return ret
  def enable_display(self):
    if self.available and self.led_brightness != 8:
      self.__inst.set_led_brightness_level(8)
      print('Purifier(%s) setting display to %d, led_brightness = %d' % (self.name, 8, self.led_brightness))
  def disable_display(self):
    if self.available and self.led_brightness != 0:
      self.__inst.set_led_brightness_level(0)
      print('Purifier(%s) setting display to %d, led_brightness = %d' % (self.name, 0, self.led_brightness))
  def set_rpm(self, newrpm):
    if self.available and abs(self.current_rpm - newrpm) > 20:
      if newrpm <= 400:
        if self.mode != airpurifier_miot.OperationMode.Silent:
            self.__inst.set_mode(airpurifier_miot.OperationMode.Silent)
        print('Purifier(%s) setting silent RPM to %d, current_rpm = %d' % (self.name, newrpm, self.current_rpm))
      else:
        self.__inst.set_favorite_rpm(newrpm)
        if self.mode != airpurifier_miot.OperationMode.Favorite:
            self.__inst.set_mode(airpurifier_miot.OperationMode.Favorite)
        print('Purifier(%s) setting favourite RPM to %d, current_rpm = %d' % (self.name, newrpm, self.current_rpm))

purifiers = {
  'Kitchen' : Purifier('192.168.xxx.xx0', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Kitchen'),
  'Master Bedroom' : Purifier('192.168.xxx.xx1', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Master Bedroom'),
  'Kids Bedroom' : Purifier('192.168.xxx.xx2', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Kids Bedroom'),
  'Spare Bedroom' : Purifier('192.168.xxx.xx3', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Spare Bedroom'),
}

while True:
  now = time.localtime()
  for name in purifiers:
    p = purifiers[name]
    p.update()
    print(time.asctime(now), p)
    if p.available:
      if p.powered_on:
        try:
          if 'Kitchen' in p.name or (now.tm_hour >= 9 and now.tm_hour <= 21):
            # Daytime running
            p.enable_display()
            if p.air_ppm >= 5:
              new_rpm = 1100 + p.air_ppm * 10
              if new_rpm > 2200:
                new_rpm = 2200
              new_rpm -= new_rpm % 10
              p.set_rpm(new_rpm)
            else:
              p.set_rpm(1100)
            continue
          # Nighttime running
          p.disable_display()
          p.set_rpm(700)
        except (airpurifier_miot.AirPurifierMiotException, DeviceException) as e:
          print("Failed to set", p.ip, "(" + p.name + ") due to", repr(e))

  if now.tm_hour >= 22 and now.tm_min > 1:
    print("It is after 22.01pm, exiting!")
    break
  #time.sleep(10)

Sure, it’s not pretty, but it does the job until support for these purifiers lands into Home Assistant. I have it running inside a cronjob which launches at 08.59am, then the script exits itself at 22.02pm. This is to prevent constant WiFi traffic at night time as I have one of these units right next to my head in my bedroom. As the script runs, it outputs a constant sequence of logging which looks like:

Sun Feb 21 00:13:15 2021 Purifier(Kitchen) available=1 powered_on=1 air_ppm=0 led_brightness=8 current_rpm=1100 filter_hours_used=87 filter_life_remaining=97%
Sun Feb 21 00:13:15 2021 Purifier(Master Bedroom) available=1 powered_on=1 air_ppm=0 led_brightness=0 current_rpm=704 filter_hours_used=80 filter_life_remaining=98%
Sun Feb 21 00:13:15 2021 Purifier(Kids Bedroom) available=1 powered_on=1 air_ppm=0 led_brightness=0 current_rpm=704 filter_hours_used=81 filter_life_remaining=98%
Sun Feb 21 00:13:15 2021 Purifier(Spare Bedroom) available=1 powered_on=1 air_ppm=0 led_brightness=0 current_rpm=704 filter_hours_used=81 filter_life_remaining=98%
Sun Feb 21 00:13:24 2021 Purifier(Kitchen) available=1 powered_on=1 air_ppm=0 led_brightness=8 current_rpm=1104 filter_hours_used=87 filter_life_remaining=97%
...

Something a bit worrying is what happens whenever one cooks dinner, so the hob or oven is on. My script rapidly increases RPM on a per-purifier basis if its PM2.5 sensor exceeds five μg/m3, hitting the maximum 2200 RPM from 110 PM2.5 onwards. So far, we have not failed to hit at least 50 PM2.5 in the kitchen, sometimes over 300 PM2.5, though the purifier does clear it within fifteen minutes after you stop cooking. More worrying again is that this pollution gets all over the house, the other purifiers register 30 - 40 PM2.5 in our bedrooms.

Now, I knew from general reading that this is typical in UK-Irish homes which are unusually poorly ventilated by international norms, but until now it was all kinda abstract. I hadn’t really realised what it actually meant until I saw these sensors all jump throughout the house every dinner and lunch times where we cook hot food. We do have an extractor over the hob, but it’s a cheap noisy thing which doesn’t seem to extract much. So it looks like these air purifiers might do some good there too, which was not expected before I bought them.

#air-purifiers #xiaomi




Click here to see older entries


Contact the webmaster: Niall Douglas @ webmaster2<at symbol>nedprod.com (Last updated: 2019-03-20 20:35:06 +0000 UTC)