Jump to content

IoT / microcontroller based power switching


TerryE

Recommended Posts

My topic, SunAmp PV spares and maintenance issue,  has triggered a couple of classic "Boffin's corner" discussions for me.  and the first is "What is the best way to switch power circuits using Arduino-class modules?

 

If we assume a 240V/16A resistive load as the target of control, then this is well above the power rating for the range of low price I2C / USB / TTL relay boards that are typically rated as around 1A operating current at 240V AC.  My personal preference is to have a clear separation between the control side which is typically at 5V or less -- but anyway at a max current and voltage rating where there isn't an electrical safety issue -- and the 240V side which needs to conform to BRegs for electrical safety.  I can see two separate approaches here:

  • The first is to use CE-approved off-the-shelf products to do the power switching.  An example here (though possibly not the best) is the Sonoff TH16 series IoT relays.  The advantage of this device is that proprietary control software can be easily replaced with Tasmota or your own control software and typically implementing a MQTT control protocol.  This also means that the device can also be directly controlled by your HA system.
  • The second is to use a quality CE-compliant module that is TTL controlled.  I've use DIN rail-mounted Crydom SSRs for my current control system and I am considering switching to their panel mounted equivalents.  Devices which accept TTL signalling levesl make interfacing these to an IoT processor straightforward.  Even though many ESP and Atmel devices can't provide 5V 50mA outputs, my approach here is to use a MSP23008A I2C to 8 TTL port chip which can be controlled by a <10mA 3.3V I2C input and this can output at the TTL levels needed to operate the SSRs.  For those interest BigClive give a teardown of an SSR on YouTube  (this is flawed cheapie, but this videos still explains how they work).

 

SSRs have a lot of advantages for power switching but the big downside is the need for thermal management.  They give off roughly 1W / A switched or ~12W when running a 3kW resistive load, but if you are radiating this from a 300×600mm panel then this panel needs to be roughly a Δt of 10°C above ambient to dump this heat radiantly.

 

You can get 16A rated relays and contactors and switching resistive loads is a lot more benign than inductive ones, but you still need some spark suppression circuitry around the relay and most relays need a reasonable power to operate, but you can get 16A relay modules such as this one which contains the extra protection circuitry on module , though I don't know how good they are.

 

So what are views of other boffins in this area: @JSHarris, @Ed Davies, @ProDave, @PeterW, @MikeSharp01 for example?

 

Edited by TerryE
Link to comment
Share on other sites

I switch my immersion heater with a solid state relay.  That provides the isolation between the controller and the mains.

 

I chose a SSR that has a 5V input.  But I still did not want to switch it directly from an Arduino output pin.  So it is switched with a PNP transistor that pulls the SSR input pin up to 5V when the Arduino output goes low.  So the Arduino only sees a tiny output current when switching and would be unlikely to ever be damaged by any reasonably conceivable fault.

 

Of course I chose a SSR rather than any form of mechanical relay due to the frequency of switching (turned on for anything between 0% and 100% of every half second time period. you would not want to be switching a mechanical relay at 2Hz all day long)

 

Edit to add, I also chose a 25A SSR for the immersion heater.

 

Re heatsinks, I just opened my box of heatsinks and chose one that looked about right. It runs just warm to the touch on a good day when the PV is generating well and heating the HW tank.

  • Like 1
Link to comment
Share on other sites

My immersion diverter uses a 25 A Crydom SSR, switched directly from a microcontroller pin (5 V at ~8 mA, well within the ~20 mA capability for a PIC pin).  The SSR I used was a panel mount D2425, which has an input range of 3 - 32 VDC, so will just about work OK from a 3.3 V logic output (it needs ~6 to 7 mA to turn on).  The SSR is just bolted to the back of a small diecast box; that seems fine as a heatsink.  The dissipation when turned on is about 15 W maximum, according to the datasheet, but in practice it seems to be less than this, as the box barely gets warm to the touch.  It's been working continuously for a few years now, with no glitches or problems.

  • Like 1
Link to comment
Share on other sites

1 hour ago, TerryE said:

My personal preference is to have a clear separation between the control side which is typically at 5V or less -- … -- and the 240V side

 

Mine too.

 

My only recent experience of switching mains with microprocessors is using the Sonoff TH16 which controls my fridge.

 

What I envisage for most of the controls of my house is using a separate Wi-Fi-connected microprocessor running a relay board. Control via MQTT with messages like “relay/A49C73A4AE30/03 1” to turn relay 3 of the board with that MAC address on. Probably a few instances in different parts of the house. That's likely fine for small loads (lights, motorised valves, perhaps some pumps noting their inductivness). Where something a bit heavier needs switching then the directly microprocessor controlled relays would switch additional 230V-coil relays.

 

I don't think I'll need anything which needs switching at high frequency (like a PV diverter) so the only likely use I'll have for SSRs is in the battery management system for last-ditch emergency protection of the battery bank if a cell is becoming over charged or discharged. The main reason for using SSRs there is the need to switch fairly brutal loads (120 amps at 50 volts DC) which could be done with a contactor but those themselves would have a not insignificant power draw 24h/day. I've also had thoughts about latching relays for this job.

  • Like 1
Link to comment
Share on other sites

3 hours ago, TerryE said:

MQTT

Can't help thinking that something like MQTT will be the core of IOT but will need to much more sophisticated and massively more secure, which I notice is already being addressed, but robust it isn't yet if you want 'things' on a global scale. We need to standardise, that much I know - Arduino is a standard and ridiculously cheap for what it is, the advent of Blocky for creating and modifying code (5 year olds can use it) means we can confidently develop stuff that won't require our eternal presence to keep it running. There are still some nuts to crack though and, you will have heard me banging on about meshes, these things still need work.

 

On the controlling front I have a board, I made years ago, that allows me to opto isolate TTL inputs and outputs, 12 per board, using Darlington drivers on the outputs so I think I could get 200mA per channel at 24V - which was the control voltage I chose because we use it on all our commercial work but I like the little TTL driver chip and given you do get, from responsible manufacturers real products (unlike the ones shown in the video you posted @TerryE - even though very amusing), good isolation you can have your expensive PC / Tablet connected and not worry about it getting the full 240V, or worse, up its chuff!

3 hours ago, TerryE said:

radiating this from a 300×600mm panel then this panel needs to be roughly a Δt of 10°C

And that is just from one of them running the Immersion / Willis or whatever. 

 

I do have a concern about the heat output of SSR's for two reasons, and I had occasion to be somewhat upset by them the week before last as I have one on our pressurisation set in the loft here at millstone manor which, when the loft temperature reached 40+ the Δt took the thermal trip on the heatsink over its limit and we lost water pressure - 'Mike why is there no water coming out of my bath tap', trip needs a reset which I madly left in the loft! I have now copied it down into the main control panel and up-rated the trip from 55DegC to 65degC that should give me few years even with global warming as it is. Anyway my reasons..... 

 

Firstly is that the heat is energy consumption I don't want and the second is that the heat is also unwanted. Perhaps we should put the SSR's outside the thermal envelope but either way it is waste. Traditional relays are much less power hungry but cannot be switched in PWM type situations so its horses for courses. I suppose we could imagine, making any required adjustments to internals of the SSR so it could cope, a hybrid system of an SSR with a relay contact across it so you turn on the SSR, pull in the relay and turn off the SSR if you want PWM don't energise the relay if you only want continuous just use the relay.  (Perhaps I have had too much beer!)

 

 

 

 

 

Link to comment
Share on other sites

14 hours ago, MikeSharp01 said:

something like MQTT will be the core of IOT but will need to much more sophisticated and massively more secure, which I notice is already being addressed, but robust it isn't yet if you want 'things' on a global scale.

@MikeSharp01, This is really the subject of a separate boffin's topic but I really dislike the whole concept of allowing any global access to or from IoT devices.  The vulnerabilities are just too great IMO when you aren't using a proper locked-down OS.  I far prefer the concept of all my IoT devices being on a private dedicated control LAN and the only device which bridges to the general LAN is some locked down trusted device such as the HA system.  I feel that HTTPS is just the wrong protocol because whole issue of certificate negotiation / validation is difficult to implement within a private LAN and the whole mbedTLS stack is just far too bloated in terms of RAM requirements for the current generation IoT devices.

 

In terms of isolation all current (respectable) SSRs and most relay modules include opto isolation.  I also socket my MSP23008A's making them trivially on-site replaceable.  I've also played around with ULN2803a's which are a nice packed Darlington implementation.

 

Have you though about any preferred relay module alternative to SSRs? 

 

 

Link to comment
Share on other sites

29 minutes ago, TerryE said:

ULN2803

I must have about a 1000 of them in my chips box! really useful little bugger. 

 

30 minutes ago, TerryE said:

but I really dislike the whole concept of allowing any global access to or from IoT devices

True / agree but there is something odd about an IOT that is really just an island of a few things. I guess its just about squeezing the security down into the things - but for another day.

Link to comment
Share on other sites

4 minutes ago, MikeSharp01 said:

but there is something odd about an IOT that is really just an island of a few things

 

Maybe in some future we might have all devices publicly addressable everywhere, but I am a bit more paranoid.  Only my HA system can talk to my devices, and if I want to talk to them or allow them to talk to me then this all goes through the HA system.

Edited by TerryE
Link to comment
Share on other sites

17 minutes ago, MikeSharp01 said:
54 minutes ago, TerryE said:

ULN2803

I must have about a 1000 of them in my chips box! really useful little bugger. 

Is it worth getting some so that I can connect my collection of RPi's to other things like an SSR.

I have, so far, shied away from playing with 230V stuff.  It does not scare me, just that I have not wanted to smoke any of my Pi's.

Link to comment
Share on other sites

58 minutes ago, TerryE said:

This is really the subject of a separate boffin's topic but I really dislike the whole concept of allowing any global access to or from IoT devices.

This is something I would like to know more about.  It really should not be hard to design something that only the owner has access to.

30+ years ago, I was chatting to an software engineer and he said there was a system/protocol for making sure that software did what you wanted, without surprises.

Seems something like that is needed now, any idea what he was on about (he was Belfast Irish, so he may have said something very different).

Edited by SteamyTea
Link to comment
Share on other sites

7 minutes ago, TerryE said:

Only my HA system can talk to my devices, and if I want to talk to them or allow them to talk to me then this all goes through the HA system.

Makes perfect sense but might not be an analog for open communications and I fully appreciate the challenges - but I cannot help thinking that there must be an answer.

Link to comment
Share on other sites

6 minutes ago, SteamyTea said:

Is it worth getting some so that I can connect my collection of RPi's to other things like an SSR.

Yep - no need to worry about mains stuff provided you have proper leakage protection back at your fuse board, are respectful of the potential (pardon the pun) dangers and as long as you don't buy clone copies of SSRs (or if you do you know what you are doing) you have more than adequate protection and those ULN's will drive 8 SSRs all day but if you want really fast switching you may have trouble I think its a few nano seconds on / off.

Link to comment
Share on other sites

Most SSRs don't switch very fast, as they are limited by the optoisolator.  A few µs is probably about as good as most manage, but that's fine for mains switching.  No real need to worry about isolation, as the built in optoisolator provides a high degree of safety for low voltage connected stuff.  Probably a good idea to stick the mains stuff in it's own enclosure, though, and just run isolated wires across to the low voltage stuff.

Link to comment
Share on other sites

Regarding power-switching, I'm keen to get all the mains level control onto DIN rails and into closed cabinets. I think this is why, after searching all the more modern open source alternatives, I'm defaulting to using Loxone for most of my core systems controls (lighting + heating, and probably shading too purely because Internorm+Loxone have a tie in) as it's all packaged in convenient DIN form. I first came across SSR in their (5 year old) article on making a DIY solar diverter, and showed a DIN rail mountable SSR so that all seemed logical: put it in the same CU box as the miniserver (or extension) and it can all be neatly locked away together.

 

More I read and look at this though, the more I realize the logic for immersion heater as redirect is to always use it as the final / lowest priority device in the chain, as it can be modulated to "use up the gaps" that can't be allocated to the fixed quantum demanded by other appliances. Thus... any "off the shelf" Solar PV that just always left on auto mode will probably offer no less functionally than having direct control of it from HA - so long as I can factor its live usage into any calcs about other devices to turn on/off based on current generation.

 

Regardless which way I go, this also made me realize while we'll have a dual immersion tank, only one of them needs the PWM modulation. The other I can just power through a mechanical relay (contactor) when we have >3kW of excess generation (and/or fire up the ASHP if the controls for that are compliant enough for it), and the automatic modulated solar redirect (whatever solution chosen) will use up any slack still available on top of that.

Edited by joth
Link to comment
Share on other sites

20 minutes ago, SteamyTea said:

Is it worth getting some so that I can connect my collection of RPi's to other things like an SSR.

I have, so far, shied away from playing with 230V stuff.  It does not scare me, just that I have not wanted to smoke any of my Pi's.

 

Nick, have a look at the video tear-down that linked to above. The control side of the SSR is opto-isolated from the power side.  You just need to drive the SSR with TTL level signals, can use something like an MSP23008A 8 port multiplex and drive this using I2C from an RPi.  Darlingtons are really used to protect / drive larger currents, e.g. DC input contactors typically use 12V or 24V DC.  For <16A you might prefer to use SonOff devices discussed above.  You can reflash the propitiatory onboard firmware wit Tasmota (various how-to YouTube videos available).

 

If you have low power stuff then you can buy opto-isolated 12,4 and 8 relay boards that you can drive direct from your RPi GPIOs.  For an extra £5-10 you can get the equivalent with a USB interface.

Link to comment
Share on other sites

57 minutes ago, joth said:

More I read and look at this though, the more I realize the logic for immersion heater as redirect is to always use it as the final / lowest priority device in the chain, as it can be modulated to "use up the gaps" that can't be allocated to the fixed quantum demanded by other appliances. Thus... any "off the shelf" Solar PV that just always left on auto mode will probably offer no less functionally than having direct control of it from HA - so long as I can factor its live usage into any calcs about other devices to turn on/off based on current generation.

 

 

This is what all the commercial, off-the-shelf, PV diverters do, and also what mine does.  If the house demand rises whilst the PV system is generating, then PV diversion reduces or stops.

Link to comment
Share on other sites

3 hours ago, TerryE said:

I far prefer the concept of all my IoT devices being on a private dedicated control LAN and the only device which bridges to the general LAN is some locked down trusted device such as the HA system. 

 

Again, yep: intranet of thingummies. I haven't done it yet as there's no control in my current setup [¹]  but my notion is to have a router (probably running some flavour of BSD) which limits communications between various LANs: a DMZ/guest LAN, an office LAN and a control/IoT LAN. The only communication in/out of the IoT LAN allowed would be to/from the main HA hub allowing it to use NTP to get the time and for me to SSH in. Any web access would then be tunnelled over SSH for my personal use. If I decided to publish any live data for any reason then there'd also need to be a path out of the IoT LAN for the Hub to send the data elsewhere for that.

 

[¹] apart from the fridge which is done within the attached Sonoff (not controlled over MQTT or anything)

Edited by Ed Davies
Link to comment
Share on other sites

There's a lot of mentions of Arduinos in this thread, and the odd mention of RPi, but for my money both of those are overkill.

 

The best option (IMO) is either to go with Tasmota on a Wemos D1 Mini: https://github.com/arendst/Sonoff-Tasmota/wiki/Wemos-D1-Mini

 

You can pick these up at between £2 and £3 a piece on eBay. Built on the same ESP8266 base as the Sonoffs (so with built-in WiFi), but you can roll-your-own interfaces for anything you like.  Tasmota means you get MQTT (for any Home Automation server) and scripting (with the latest Tasmota version) built-in.

 

 

Link to comment
Share on other sites

2 minutes ago, Ed Davies said:

 

Again, yep: intranet of thingummies. I haven't done it yet as there's no control in my current setup [¹]  but my notion is to have a router (probably running some flavour of BSD) which limits communications between various LANs: a DMZ/guest LAN, an office LAN and a control/IoT LAN. The only communication in/out of the IoT LAN allowed would be to/from the main HA hub allowing it to use NTP to get the time and for me to SSH in. Any web access would then be tunnelled over SSH for my personal use. If I decided to publish any live data for any reason then there'd also need to be a path out of the IoT LAN for the Hub to send the data elsewhere for that.

 

[¹] apart from the fridge which is done within the attached Sonoff (not controlled over MQTT or anything)

 

Sounds very similar to my setup.

 

Take a look at OpenHAB: https://www.openhab.org/

 

Self-contained rules-based HA engine with good MQTT support. Runs nicely on a RPi.

Link to comment
Share on other sites

@joth,

 

9 hours ago, joth said:

Regardless which way I go, this also made me realize while we'll have a dual immersion tank, only one of them needs the PWM modulation.

 

This struck a cord for me and something that I leant through my slab modelling.  I described in this in my blog post Plumbing Design – Part II, and which incidentally has been supported by 2 years of actual data on slab performance.  If we want to limit the output temperature of the inline heating element to say 75°C, then from "cold" the PCM cells will be in solid phase and may 30+°C colder than the circulation input.  The phase transition alone from melting the salt will absorb the full 2.8kW output of the element.  The cells will reach thermal equilibrium at the melt point of around 58°C (is that correct @Nickfromwales)  with the absorbed heat melting the salt and changing the % liquid.  At some point the % of solid salt and the melt rate will be such that for the flow rate of the pump, the cells will be incapable of 2.8 kW without the return water temperature rising to the point for the flow rate where the output from the element will rise above the 75°C maximum target temperature for circulation.

 

At this point we have a number of heating strategies:

  1. Stop heating and accept that the cells are only charged to say 80-90% of thermal capacity.
  2. Modulate the heat output of the element down and in practice this means some form of PWM modulation.  OK, the modulation epochs used to control something like a stepper motor aren't needed, but we do need to keep the temperature ripple on the circulating water within some form of tramline, say <5°C.  I need to do the sums but the on-off cycle is probably in the 10s of seconds rather than sub-second or super-minute.

Case 2 makes using a relay a no-no, IMO, and pretty much mandates the use of a zero-crossing SSD.  The pump relay is only switching a few times a  day and is carrying maybe 2-300 mA so a relay would work OK here.

 

@JSHarris would you agree with this?

 

Edited by TerryE
Link to comment
Share on other sites

25 minutes ago, TerryE said:

I need to do the sums but the on-off cycle is probably in the 10s of seconds rather than sub-second or super-minute.

If you know the material the element is made from, and the mass, you can work out how fast it will heat up for a given energy input.

That may seem an odd way to calculate it, and you need to take thermal losses from the surround fluid into account, but should work.

Alternatively, get an element stick it in a bucket of water, and do some timed test (my preferred method), then model from the data.

Link to comment
Share on other sites

or stick some instrumentation on the SunAmp that is still working to work out its operating characteristics :)  Taking the element out of the SA is going to be a total PITA.

 

Edited by TerryE
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...