Martin's corner on the web

Smart IoT solar hot water tank controller

I am working on a smart IoT controller for my solar hot water tank and I need to be able to control its mode of operation over the Internet. My plan is to have the controller subscribe to an emonCMS feed and depending on its value run in different modes (manual on, manual off, auto and anti-freeze). I will be able to control it with my phone or laptop from anywhere using small HTML page that will change the value of the emonCMS feed. The controller will need to poll the emoncms feed periodically, say once a minute, and adjust its mode of operation accordingly. The controller can also check feeds that contain weather data, including weather forecast, to make ‘informed decisions’.

To state the problem: now that it is autumn (same is valid for spring), we are seeing less sunshine both because of shorter day and clouds. That means less solar hot water at the end of a cloudy day. During the winter we use another water tank, that is directly connected to the heat pump, but it is not so cold outside for us to use heating yet. Fortunately the solar hot water tank does have an electric heater element in it and I can briefly switch it on to ramp up the temperature to desired value (if necessary). I have previously analyzed our hot water usage habits and identified two usage peaks, one at 10am and one at 8pm, the 8pm peak is when everybody at home takes a shower before bedtime, so I’ll need to ensure higher water tank temperature then compared to the morning use. So the plan is to have the controller (if running in auto mode) check the hot water tank’s temperature at 4am and make sure that the 220l water tank is at least 45 degrees C for our morning use peak at 10am. We have cheaper tariff for electricity till 6am, so I am looking into the last possible time to switch on the heater element, so that the tank reaches 45 degrees C by 6am when the cheap tariff ends. That is an easy calculation knowing the fixed volume, current temperature, target temperature and that the heater element is 2kW. The later we switch the heater element on, the less heat loss will occur (overkill alert sounding in the distance). The 8pm setpoint will be 55 degrees C, the controller will only turn the heater element, if that temperature wasn’t reached by 6pm of the day. The controller will know the time of day by intercepting the wireless time packets that my IoT gateway sends out every minute.

I have updated the uIoT gateway code to allow remote nodes to poll it for emoncms feed value. It is a bit tricky as it is a non-blocking operation and it is done while routing the wireless transmissions to emoncms. The Ethercard library is pretty limited in handling multiple packets, so it is quite possible that a response from emoncms gets lost, if in the meantime another post was made. That means that the node will get a response with some high probability, but not every time. It just needs to poll frequently enough. I say once a minute is good enough. The nodes request emoncms feed value from the gateway by sending a packet to it that has a special structure:

The packet must have the DST field set to the gateway’s node ID, this tells the gateway that it is being queried for an emoncms value. The data structure it expects in this case is as follows:

typedef struct { byte node_id; unsigned int feed_id; float feed_val;} askStruct;

I reuse the same structure for sending the reply, only node_id and feed_id are required for the query.

So when the gateway receives such packet it will query emoncms for the feed_id and reply back with its value using the same payload structure. Feed value is of type float.

Here is a quick test using Jeelab’s RF12DEMO sketch; I am querying the gateway (node_id 16) for emoncms feed 17991’s value by issuing “27,70,71,16s” command in the sketch (the querying node has ID of 27). The gateway responds back with the expected payload structure, note the added 4 bytes for the float value of the emoncms feed:

subscribe

Here is how the hardware is taking shape, it is a small box with Funky v2 and the Ciseco bistable relay that wrote about recently. There is a port for a DS18B20 temperature sensor, that will measure the tank temperature. Power is provided by an old Nokia phone charger, I ran out of microUSB power adapters and decided to re-use that one:IMG_2956 IMG_2955

The firmware is still in progress, it will implement the outlined above functionality.

Isn’t that a nice example of an IoT ‘thing’?

 

 

 

3 thoughts on “Smart IoT solar hot water tank controller

  1. Perico

    yep!. It is.

    you want to request a feed once per minute. This is the sortest period you think you can ask for one feed?. Let’s say emoncms is in your local net, in your raspi. How fast do you think that you could ask for one feed?…10s?.

    Not asking for any reason, just wondering 😉

    1. Martin Post author

      It probably depends on how many nodes will query the gateway, if you have 5 nodes asking for feed value every 10 sec, that may put the gateway in stress. Non time critical nodes can poll less frequntly

  2. Pingback: Martin's corner on the web