Raspberry Pi Boiler Control Uses A Webcam To Read The Analog Gauge

sub-image

One of the biggest problems with home automation is trying to interface with old or analog devices. Do you upgrade the device just so you can automate it? Or do you find a workaround like [Seb] did?

[Seb] doesn’t have on-demand hot water, and as such has to turn on his boiler if he wants to have a hot bath or shower. Not very convenient having to wake up an hour early in the morning just to turn the boiler on so he can have a morning shower! Nonplussed with having to continue putting up with this, he decided to try his hand at home automation using a Raspberry Pi.

The problem is there’s no easy way to have feedback on what the boiler is doing — sure he can turn it on and off using a mains relay with the Pi’s GPIO, but how can he easily measure the temperature inside the boiler?

The answer? A webcam! [Seb] took an old cheap webcam and mounted it in front of the temperature gauge on his boiler. He then wrote a simple python script to count the pixels using an OpenCV library — when those pixels turn red, the needle is at his ideal temperature (45C). Complex? A little bit, but the project only cost him all of what, $35? Gotta love how cheap Raspberry Pi’s are!

59 thoughts on “Raspberry Pi Boiler Control Uses A Webcam To Read The Analog Gauge

  1. Counting the red pixels at part of the image? Man, that’s really the ghetto way of doing it.
    But I kinda like it. It has that hackish, bare-minimum vibe to it ;)

    1. A webcam and embedded computer is “bare minimum”?

      Not really. Bare minimum would’ve been replacing the gauge with a thermostatic control, which seems to run about $30. And this didn’t cost him $37 – it cost him hours of programming, the hardware (quite a bit more than $37, if you count the webcam, the relay, etc) and then there’s the electric bill for the Pi (here in the US, you can figure $1/W/year, roughly. Electricity in Europe/UK is far more expensive.)

      This is what happens when arrogance meets DIY drive. It never occurs to you that the problem you’re trying to solve already has a very simple, cheap, reliable solution.

      Also: water heaters fall firmly into the category of appliances which, if they’re more than about 10-20 years old, are costing more in efficiency loss than the cost of purchasing a new, more efficient unit.

      1. No, not a webcam and a computer.
        Yes, counting red pixels in a predefined area when you need to detect something in an image.

        And your comment seems to be where arrogance meets assumptions and reading comprehension.

      2. Au contraire. Maybe for a homeowner, but in the real world, people are often restricted from altering original equipment for many reasons, ranging from liability to expense to red tape or even reluctance to embrace change. We don’t know the details.

        The essence of hacking is to side-step the obvious. He’s renting. Was this the best way to detect the pointer position? Maybe not – but it is an excellent example of thinking outside the box. This is kind of like the door openers kids hang on the dorm room knobs – it gets the job done, it may be overkill and it’s clearly a hack (judging from the response of professionals) so I say – Bravo. He got to play with openCV, a double bonus.

      3. The development time, assembly and programming all count as leisure time. Unless they’re less than the commercial solution would’ve cost, then it counts as money saved! Making it yourself is what people do as a hobby, for fun.

        I think it’s a bit extravagant to use a digital camera to literally “read” a meter, but it’s also funny, and impressive, that it’s even possible these days! Modern technology, eh? Computing power the NSA probably killed a few people over, a few decades ago, and now it’s replacing a thermistor!

        The fact he’s controlling it with a relay implies, to me, it’s using an electric heating element, which haven’t really increased in efficiency since ever. Equally the power to run the Pi will be insignificant compared to the saving on running the heater. You expect wasted heat from a water heater, the handful of watts the Pi uses won’t make a difference.

        1. There are electrically controlled gas and oil burning water heaters (the latter now becoming uneconomical to operate) as well as heat pump water heaters. In particular, heat pump water heaters are 3-4 times as efficient as conventional electric water heaters.

          1. Yes I know, but I imagine controlling them is more than flipping a mains relay. The use of a mains relay implies he’s handling mains current, ie an electric heater. Interfacing to a gas / oil one I guess would be a bit more complex.

            My own house’s heating, on-demand gas and sensible as it is, allows an RF remote panel for you to set timer patterns on. It’s a piece of crap. Shortly after I moved in I had to have an engineer round, who informed me of it’s crap-piecefulness, apparently they’re used a lot. I asked him just to bypass it, and now my heating comes on whenever I get cold and go work the switch. Much sensibler.

    1. Good idea. It might even work with some black electrical tape and a red LED over the position – the LEDs can be pulsed and used to detect the reflection. And without the need for a webcam, this could be done by an Arduino Pro mini – at 1/10th the cost of a Raspberry Pi.

      1. Hi. I’m Seb, the guy who did the project. I wanted to be minimum invasive. This was not my boiler, it’s the land lord’s one. I staying in a rented flat. I didn’t want to put some wholes into the boiler. And the raspberry is used because I need to start it remote from e-mail.

        1. With those requirements, I can’t thing of much better than what you did. Maybe a green LED could sense the temperature dial through the glass – the white background should reflect a lot of green, while the red dial should be much darker in the green spectrum.

      2. Better with a non-red LED, to tell the difference between red and white. Using the red spectrum, the difference in brightness won’t be much. Green would be better. Or blue. But I’m sick to death of blue LEDs infesting everything, since they finally started making cheap ones a few years ago, so I’d take green. My new ebook has a blue / green changing LED. What’s the point of that? WTF does blue mean?

        I wouldn’t try using the LED as it’s own sensor, you’d need to switch over functions in the time it takes light to travel 2cm, that might not even be time for the LED’s internal capacitance to discharge. I won’t do the maths, but in the time light travels 2cm the electricity in the circuit would have to travel down the wire, while instructions in the microcontroller zoomed around opening and closing switches.

        So I’d use a separate sensor. A photodiode or LDR, fast reponse isn’t needed. You could do it without a microncontroller, although you may as well use one for the versatility and price. Have both sensors enclosed in small tubes so no light leaks sideways. With green or blue light you should get a nice definite difference from the sensor. You could even put a green or blue filter in front of the sensor.

        1. I say “both sensors” I of course mean the light source and the sensor. And by microcontroller I was thinking something more AVR / Arduino-like. You can get them with network connections now, even running little HTTP daemons. If it has direct Internet access, it’s easy to send mail through SMTP port 25, the protocol’s really easy. Just a small 2-way conversation over port 25, wait for the right responses and send what’s necessary.

  2. I wonder why openCV is needed. Just average the colors for that block and wait for the average to be red.. Seems like a simple thing to code without openCV.

      1. I was thinking the same, but then why not go all the way to actually recognize the needle position in the whole display and add fail safe things as well? (like if the camera drops or the LED dies or anything else….)

        1. You would not need OpenCV even for that. You could just check for the red of the center of the pointer, the red on the danger area of the dial, and a spot of white on the face and maybe a bit of black of some of the text. If any of the points are not there you turn off the boiler and and send a message to the user.
          Now if you wanted to read the temp from the gauge OpenCV would probably be the path of least resistance. Frankly using OpenCV may just be the path of least resistance. It might be using a sledgehammer to kill a fly but if the sledgehammer is free why not?

      1. The reason for multiple safety features is to try and avoid the boom. Then if one safety system fails then the next will hopefully kick in and so on and so on until boom. Plumbing system are generally designed to fail safe. Adding this my first reaction was booommmmmm

    1. The boiler most likely has it’s own internal sensor that tries to keep the water somewhere, just not at the lower temp desired. When I was in Europe, the hot water was really hot, so I’d guess somewhere around 50-60C, which is probably where this one wants to run at.

      The real hack is taking a small tank water heater/boiler, and adding the capability to be a near on-demand setup. You have to know about 5-10 minutes ahead of when you want hot water, so this isn’t really an instant hot water heater replacement, but if you have the 5 minute flexibility, this would seem a fairly good electric saver.

    2. Hi. I’m Seb, the guy who did the project. I thought about that too. But if the linux hangs, the boiler still has an internal thermocouple that disconnects the power so I’m on the safe side. The raspberry pi is used so I can start it via e-mail.

      1. You might want to use the watchdog timer on the Pi to solve the potential hanging issue.
        http://www.adafruit.com/blog/2013/01/18/auto-reboot-a-hung-raspberry-pi-using-the-on-board-watchdog-timer-piday-raspberrypi-raspberry_pi/

        Do not let people bug you too much, including me. For some of of when we see a hack the first thing we do is think about how to improve it or optimize it that is me. For others it seems to be a chance to show off that they could do it better with just a relay and 555 or better a single transistor. Other will just say buy x and others hate everything.

        Take a look at the good natured suggestions and take what you want from them and ignore the rest.
        If you can activate it from an email why not also use Google Calendar? You could set up appointments for the boiler to turn on.

  3. ??? I’ve never seen a water heater that required manual control except for a very ancient demand heater that simply has a pilot light and a valve to heat water flowing through a copper coil. As a guess I’d say that relic is about 100 years old. Otherwise they’ve all had mechanical thermostats to maintain the temperature. If this is an effort to save energy it’s certainly not cost effective or sensible.

    Calling it a “boiler” when it’s not supposed to get that hot is probably an indication that something is amiss.

    1. Ah, a voice of reason.

      My HVAC senses were tingling when I read this. Step one would be to install a proper control system from a proper plumbing and heating vendor, and if you still think the “boiler” (looks like a small tank-type electric hot water heater to me, but what do I know) is using too much energy, insulate it better.

      FYI: Devices like this are designed to maintain a certain temperature at all times. Excessive thermal cycling causes early failure. Replacing the unit every few years will be a lot more expensive than the cost of the energy to have it maintain temp.

      If you really don’t want to keep the water at temp, get a good quality tankless system.

      1. Glad to hear you two know what you’re talking about. Of course the boiler has its own thermostat controlling the temperature, so to add an additional thermostat control only seems to add more inefficiency to the system. I agree that the additional cycling is only going to add to the additional wear of the unit. You can usually adjust the temperature set point on the boiler itself.

        I do, however, like the look of this for scheduling purposes. It’s fine to enable the boiler a set time before waking up and again before you get home so that you have hot water when you need it. You can leave it off during the day when you’re at work and save energy that way. Just let the boiler control the temperature on its own. It’s probably more efficient at it.

      2. >Devices like this are designed to maintain a certain temperature at all times.

        Ya’ll must live in the US, where 90% of the population keep 40-50 gallons of hot water on the boil at all times (well, hottish anyway). In the rest of the world, it’s very common to have smaller boilers (the english word these people use instead of “hot water heater”) when they haven’t installed on demand heating yet.

        Since they have to pay for electricity at higher rates than we, it’s not uncommon to only fire them up when you need hot rather than warm water.

        Many parts of not-america have drain pipes outside the home, and generally have what we would consider terrible and inadequate HVAC infrastructure. They get by.

        If you think this is bad, try southern china – luxury hotels install blended hot air/cold air climate control equal to anything we have in the US, and then leave the hot air turned off to save money. There is nothing quite like trying to get a comfortable temp at night, only to discover that your choices are sweltering hot and freezing cold… because the thermostat foolishly believes that warm air is available.

    1. My experience is that ‘makers’ call them leads(like in pencil leads) and long time electronic hobbyists tend to call them L.E.D.s but your milage may vary. BTW do you call it a buyoss or a B.I.O.S.? Or perhaps neemah vs N.E.M.A? For most purposes it probably doesn’t matter, even if you were to call it a ‘diode light thingy’ as long as the concept was conveyed.

  4. Hi all,
    I’m Seb the guy who did this hack.
    From the description the people seem to miss the idea.
    People call it overkill but:
    The Raspberry Pi is used because I need to start the heater by sending a e-mail with the month/day/hour.
    Also I didn’t want to put thermocouples or remove the screen because I wanted to be as minimum invasive as possible. This is not my boiler. I’m staying in a rented flat.
    The boiler has an internal thermocouple that switches it on/off but the control button doesn’t let you fix the desired temperature so you don’t really know when it will stop.

    P.S. Please excuse using the word boiler, instead of water heater. It is a water heater but I missused the therm because boiler is the way we call it in my native language(romanian).

    1. It’s what I’ve always called them too and English is my native tongue. There’s a lot of pedantry on had.

      If it achieves the main goal and meets all requirements it’s a good hack in my book. This one ticks all the boxes. Nice hack.

  5. This hack seem to bring lots of discussion on how it could be done, better, simpler, cheaper or what ever.
    At first I had the same though as bunch of people, whack the analog display out and install a digital one. But this was not an option.

    The point here: (Creator have posted comment which explain his approach.)
    Is a hack with a really nice approach to an “untouchable” device!!! (To article writer, you could use that approach instead)
    In some case, this situation is inevitable, no option to connect directly to the “thing”, and need to have a closed loop system monitory on it.

    [Seb] found a clever way to be able to start via emails and have a loop back system to close the heater when appropriate value is reach, which had to be non invasive!!!
    Thumb UP!!!

  6. Very cool – there is at least one commercial implementation useing a similar method – can’t find a link now, but it covers the analog gauge, is battery powered, uses a camera to ‘read’ the needle position and returns the ‘digital’ value over wifi. Intended for industrial use, it comes with software to calibrate the ranges.

    Pretty pricey for individual use though.

  7. Let me see if I understand…..you want the system to heat the water on demand….left on and alone it works as a normal water heater, correct?

    Now if that’s the case, you’ve found a solution. I’d like to see what your consumption is with your design and what it is if the boiler is just left on working to the normal setpoints.

    By shutting it down and turning it on as needed, you’re actually wasting an amount of energy. As long as your net improvement here saves a measurable and meaningful amount of power, then you’ve done a great thing. Otherwise it’s overkill to save just a few bucks a month.

    I expect you are saving a lot. I have an electric hot water heater/boiler that has learning circuitry and trends use over a number of days, then it heats up as needed but will cycle off automatically if the time is within a low useage region. With the effective insulation, the water stays hot for hours after shutoff….

    Good work. As long as the heater is normal and turns itself off at a high preset level, you’re fine. If however you do not know this, your design needs additional code to prevent an overheat condition.

  8. Other than remote on, there is no reason for this. This water heater has a cutoff, what is wrong with it. Is it too high? It probably can be turned down or needs to be replaced for safety.
    If your hot water stinks, turn the temp up to 137F or higher. Conserve with insulation.
    Thinking of just heating a tank to 90F or so for hand washing in a restroom? Don’t! In a word, Legionaries! Bugs. Death. Worse than Boom!

    1. City water is chlorinated to avoid that exact bacteria problem you describe. Just beware if you’re using well water. It’s also not necessary to keep it that hot all the time even with well water. Just a few hours a week is enough.

  9. To all of the haters: I’m quite sure that the better solution you could have made but didn’t is much better than the solution he could make and did. Except yours has the tiny failing of, you know, not actually existing.

  10. First year instrumentation student here. For future reliability I’d invest into a temperature switch – or a couple for redundancy. regarding previous replies, I don’t overly agree with the reliance of safety systems like pressure relief valves. Proper implementation of control should be able to prevent undesired process variables, and only fail on the rarest hardware faults. Anyways before I try to convince some of you to turn your basement into a process lab, cheers, I like to see these great ideas and see how they are implemented

  11. What a colossal waste of time. This could have been done with something as simple as a pair (or few pairs) of IR LED’s and photodiodes, if you really wanted to make it TOO complicated… If yyou didn’t consider your time to be worthless, then a $5 AC timer? Or a replacement guage with cutoff switch? What would that cost? 20 bucks??? How much time was wasted on this?

    1. I think he enjoyed making it and feels justifiably satisfied at creating something. Since he enjoyed what he did – he wasted no time. But you’ve wasted a lot of people’s time (and your own) creating nothing but negativism.
      Get a hobby, you need an outlet for your pessimism.

  12. Interesting hack but I probably would have simply added a thermistor that way I can have a robust 8bit uC do the controlling.
    As for the AC side of control things could be improved with a Solid state relay with an optical isolator so you don’t risk frying the GPIO pin on the Pi.

  13. and cue the absolute onslaught of people saying how much easer/better/cheaper/sexier this would have been if it ONLY HADN’T INVOLVED A PI BECAUSE OMG THAT’S OVERKILL

      1. I had a long reply typed out, then i decided to go and see what else you’d said. I’ll give you that he could have used a $5 timer, that would be a super simple way of controlling this thing that.

        However, just because he didn’t do it the way you would have doesn’t mean it’s a waste of time. He’s happy with it and it’s doing what he wanted it to do, so what’s your problem?

Leave a Reply to noneCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.