Central Heating Controller

Posted on
  • I have been working on an Espruino project to control my heating system. Its far from complete but I thought what I have done so far would be worth sharing:

    I have created the temperature measurement module (based on DS18B20), a bespoke scheduler module and a "ButtonSet" module to help with a touch-screen user interface (ILI9341).

    More interesting is the HttpServer module (wiz550io) which implements a REST web service.

    I put together a browser application which communicates with my Espruino using RESTful calls and in future this will allow me to control my home heating system remotely. It currently only performs read operations so I decided to make it available for demonstration of what can be done with espruino.

    The server has been running all week without any glitches (or memory leaks). It can be found at:

    http://heating.x10host.com/main.html

    Please try it out but no denial of service attacks :)

    (if it is unavailable I am probably working at it so please try again later)

    NOTE: Don't use IE - there is an unresolved issue but Chrome, Safari, Opera & Firefox seem fine also be sure to read "The Software" tab in the application for an explanation of how it works.

    EDIT: It's not always so cold - I've been away most of week!

    It's now working with IE - it turns out function.name is not available in IE yet.

  • Walked myself through the main.html and related files. Cool solution - including how to overcome the same-origin/cross-domain challenges and minimize load on Espruino.

    Making Espruino the primary server and just serving a 'bootstrapping shell' and your current x10host the place to load dynamically the content (reversing the x10host and Espruino roles) would that work for you too?

    On another note: I like your bare bones approach. There are a lot of nice frameworks out there that can do all what you do in nicely too... with must much more overhead. Applying agile to requirements of a tool/environment/infrastructure is a cool thing: just build what is needed... and nothing more.

    On some tech/coding notes:

    • In the tabs.js I noticed tabLinks and contentDivs defined as (empty) arrays, but nowhere in the code I see usage as an array - just dynamic adding and variable accessing of the respective DON node properties. With no other use in mind, a plain, literal object definition would be sufficient, would it?

      var tabLinks = {};
      var contentDivs = {};
      
    • Did you consider to use some AMD / requireJS technique for modularisation... and get cross domain access for free? - http://www.slideshare.net/anm8tr/amd-why­-what-and-how is quite a nice intro.

    • For the ButtonSet module, did you had taken a look at http://forum.espruino.com/conversations/­257540/ conversation?

    Btw, do you check your forum messages?

  • @allObjects Thanks for your feedback - really appreciated.

    You are correct about tabLinks & tabContents - not sure how that slipped through the code review process;)

    Could you explain the 'bootstrapping shell' idea please - is it basically a redirect from espruino to x10host?

    I've taken note of your comment on AMD/requireJS And am reading http://requirejs.org/docs/whyamd.html#am­d

    Your ui controls look excellent - I don't know how I missed that post - is the code available? Is it memory intensive?

    As for the forum messages - I hadn't been checking but will do.

  • UI code is downloadable - currently as inline module attached to the post (it includes also the touch screen logic).

    I started to develop modules inline because I ran out of google closure compiler allowances with my highly iterative development style: add a method, test and debug it, then next...

    Regarding memory consumption: I tried to be as terse as possible - because I myself ended up on other occasions with Out of memory. For those cases I then encoded the information: instead of an array of numbers I used a string and calculated the value from the ASCII value of the character (it is the specification of the PacMan game board as part of the (still progressing) conversation at http://forum.espruino.com/conversations/­127039... unfortunately not yet posted there (yet), because I wanted to describe the encoding... I though posted a topic discussion regarding memory consumption regarding not consumption in conversation http://forum.espruino.com/conversations/­255954 with the encoded strings in post at http://forum.espruino.com/comments/11858­853/. bs - borders - describe the islands or maze walls, ns - nodes - describe the 'points' where paths split, intersect, or make a turn, and ss - segments - describe the paths between the nodes. Since the standard PacMan game board is a raster of defined/limited size, coding within printable ASCII characters with values 33..126. The attachments include a clip of the drawing process of the borders and the initial specification and code for it . Decoding to get numeric value is method v() in lines 107..110 (ignore unused second parameter a). P.w is the raster width in pixels to fit the display (horizontally).


    3 Attachments

  • Hi @DaveNI,

    This looks great! I'm really impressed by how quickly the pages are being served up too - looks like 200ms from beginning to end to get here!

    It still looks very cold in your house though...

    How are you sending the temperature readings from different rooms to the one webpage? Is it some kind of radio, or are you doing it all over ethernet?

    I actually have to implement something like this really soon too - the usual thermostat in the hallway is doing a useless job of regulating temperature here, and during the day all I care about is keeping the 'office' warm. I've bought some EQ-3 MAX! E-TRVs in the hope that I can control them from Espruino - we'll see what happens!

    If you want to get around CORS, I think you just have to modify the server's headers. For instance:

    var http = require("http");
    http.createServer(function (req, res) {
     res.header("Access-Control-Allow-Origin"­, "*"); // <---- this
      res.writeHead(200);
      res.end("Hello World"); 
    }).listen(80);
    

    I think that should work - although your current solution seems to work fine!

    We should definitely get some kind of UI module put on the Espruino website - seems a shame to have to reimplement things each time...

  • @Gordon I'm also pleased with the speed (I'm getting 130ms from my work office).

    As for the temperature - you may have noticed that the readings are within 0.5 deg range - thats because all 5 sensors are on the breadboard at present. The breadboard is in my "workshop" which is a converted garage and doesn't hold the heat very well (hence the 13 deg!).

    I have another 5 sensors attached to a length of ethernet cable (I live in a bungalow so its easy to run the cable in the loft & have a small hole in the ceiling to run a short wire into each room.) I will use these these sensors when I go "live".

    Wireless would be good but don't suggest things like that - I'm hopeless with scope-creep as it is :)

    Those valves look excellent - hopefully you get them working. I currently only have 2 zones (heat & water) but intended to add a few more zone valves - these may provide a simpler solution requiring less plumbing (most of my rads have thermostatic valve heads).

    Thanks for the CORS info - I thought it would be more difficult but seems simple enough, especially for GETS. The JSONP is working really well & I like the way integrates so as you suggested I will keep that approach.

    One quick question - I'm planning to use this relay module for the boiler & pump (since I already have one):

    http://www.amazon.co.uk/gp/product/B007F­6Q5QU

    How far do you think this could be from espruino if the GPIO's were connected to it using CAT6 cable? I would like to get about 10m if possible. Maybe I should just try it ...

  • That relay module might be a bit small to control a pump. Its rated at 2A and a pump could well be rated more than that. Also the pump being an inductive load means that you might be better off with a relay based board.

  • I hadn't seen those Solid State boards before - as @mhoneywill says, it might be a bit close for the pump. What about these guys. Same thing, but massive massive overkill :)

    A 10m cable may be ok, but make sure you use a twisted pair of the cat6 as I guess noise could be an issue. To make it better, you could send a 5v signal rather than 3.3v.

    To do that:

    • Choose a 5v-capable pin on Espruino
    • Add a 5k pullup resistor from the pin to 'Bat' (if running off 5v)
    • Call pinMode(MyPin, "opendrain")
    • Now when you output something, you'll get the full 5v voltage swing.
  • I had a quick look at the data for the two different solid state relays just because I have looked at several relay boards off the internet and found them unsafe.
    The smaller relay mentioned here (2A) could perhaps work for a max 300W load but I would not expect it to last very long because of voltage transients on the mains voltage. It really needs some overvoltage protection circuitry.

    The 25A relay should be able to handle larger loads but may need a heatsink as it drops about 1.6V. It needs 7.5mA drive current at 12V. There is no details on how to drive it from 5V. The safest approach would be to use 7.5mA constant current drive.

    With both these relays it is important to remember that when they are not ON, there can be a substantial leakage current through the "contacts", so it is not safe to touch the wire coming from this type of relay if the other wire is connected to the mains voltage. There can be enough current flow to create a danger. Also, voltage transients can cause the relay to turn on briefly (a few ms) even if there is no drive current. So if one is used to mechanical relays it can be a surprise.

    Also, both of these relays have relatively low isolation voltage between power side and drive side, and the driving circuitry should be grounded to avoid electrical shock if there is a large voltage transient on the mains voltage that is large enough to jump the isolation barrier. The most common path for a transient is usually across the surface of the relay or the circuit board. Where many of the internet relay boards fail is that there is not enough creepage distance between power traces and drive traces, and the most common type of relay has the pins placed so that it is necessary to mill a minimum 1mm wide slot in the circuit board between power traces and drive traces, to extend the creepage path and meet safety requirements.
    Also, some of the relay boards that are offered cheaply on the internet contain relays that do not have enough isolation voltage between coil and contacts. Most users may not bother or simply are not aware of the danger, and that may be fine if all you do with the relay board is tinker in your lab. But if the board is installed and perhaps forgotten and somebody happens to touch the low voltage electronics circuitry during a thunderstorm and gets hurt then it is no fun.

  • It needs 7.5mA drive current at 12V

    Does it? It's got 3-32v written right by the input. I haven't tried mine in anger yet, but at the very least the 'active' LED lights up with the 3.3v output from the Espruino.

    I was pretty sure that these kind of triac-style solid state relays force themselves on when energised, so need a very low amount of current to get working. Only issue is they only turn off because they're connected to AC - you can't use them to drive anything that's DC.

  • I thought it would be fine since the pump is only 100W but I hadn't really considered the impact of an inductive load. The specs for the relay are:

    General purpose 2 A, 240 VAC
    Tungsten 1 A, 240 VAC
    Motor 1.60 FLA/8.60 LRA, 240 VAC

    I don't understand the FLA/LRA bit at all (I'm sure google knows!)

    Maybe I should consider standard relays - I actually thought solid state would be better since the motor may produce arching at the contacts - I'm not sure if standard circulating pumps have snubbers (if that is the correct term).

    The idea of using 5v is appreciated - I didn't know that could be done.

    I could obviously just try things out and see how it works out but the last thing I want to do is fire up the boiler with no water circulating (I was considering putting a flow switch in so that the boiler would only turn on if water was circulating) but they are difficult to come across/expensive:

    http://uk.farnell.com/gentech-internatio­nal/fs-05/flow-switch-brass-ac-10bar/dp/­1006768

    EDIT: Just wondering - has anyone bought from China, I've been a bit dubious but are the sellers usually reliable (even if delivery is a bit slow)?

  • I'll answer a few questions.

    1. Buying from China - Prompted mostly by buying an Espruino board I've bought a number of boards, displays, sensors etc from China. Apart from the delivery taking 2 to 4 weeks I've had no problems. Not had a chance to power up every board yet but build quality is good. The only item that didn't arrive was a nokia LCD module, and as soon as I notified they seller about this on ebay I got an immediate refund.

    2. I am assuming you are driving the pump directly, switching the mains to it rather that switch the pump input on a combi boiler etc. Comments above seem to confirm this. I would tend to use a relay to switch the pump. You can always put a snubber across the relay contacts http://uk.rs-online.com/web/p/rc-network­-capacitors/6727032/

    3. I agree with #tage that you should really be careful when switching mains and ensure you have proper isolation between control and mains.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Central Heating Controller

Posted by Avatar for DaveNI @DaveNI

Actions