MQTT

Heating control

0

Recently I mentioned monitoring the house with wireless sensors dotted around the place. It uses node-red to average the temperatures, and come up with a synthetic value that gets reported back to the home control system, Domoticz.

Next stage is to control the heating.

The heating system in my house is a very old design, and there’s simply a plug for the heating pump, and a plug for the boiler. When the heating is commanded to turn on by the control device (so old it’s not even a thermostat) downstairs, it really just connects these two plugs to a mains supply. The boiler and pump then turns on, and warmth ensues.

My chosen method of automation is simply to keep the heating ‘on’ all the time, and have some sort of device plugged in to the plugs in order to turn them on and off remotely. I want this to be completely retrofittable, so we can remove or change it at a later date without massive amounts of rewiring.

My initial thought was just to use a couple of LightwaveRF appliance modules, but I had a USB controlled dual relay floating around that I long planned to control the TV with, but never quite managed to get around to. Additionally, and conveniently, up the loft there’s a laptop that I use for transcoding the satellite feed to IPTV (with TVHeadend), so it was a simple case of hooking the USB board up to that laptop and getting some software on to it.

Also, to make it a bit safer, and along with the retrofitting feature, I opted to put the relay board into a little dual gang enclosure, and wire in some 13A sockets that I had in the garage.

The end result is a little deamon called mqtt-usb-relay that sits and listens for MQTT messages and then act upon them to turn the USB connected relays on and off. It subscribes to the /raw/`hostname -f`/usb-relay/#, topic, and simply takes the last component of the topic as the relay number to control, and the message as the state to turn the relay to.

Now, doing this ‘correctly’ would involve parsing the JSON output of the 3rd party mqtt.js script for Domoticz, but I decided to keep things simple and to use the On and Off Actions built into Domoticz to trigger simple mosquitto_pub events.

To do this, just create the dummy switch in Domoticz, and in the On/Off Action field, stick in commands similar to this.

script://///usr/bin/mosquitto_pub -h mqtt.vpn.glasgownet.com -t /raw/wmlp1000.vpn.glasgownet.com/usb-relay/1 -m 1

Job done. The heating can now be controlled from Domoticz. It’s not extensive control over zones or power levels of the boiler (although I have an idea for that), but it can certainly command the ‘MORE HEAT’ desire, and maybe one day I’ll install wireless TRVs on the radiators.

Household temperature monitoring

0

I’ve had it in my mind to control the heating of the house via the computer for a while now, but my first requirement was always to monitor the environment, so the computer can at least make an informed decision about whether the heating is *actually* required.

A while ago I purchased an RFXCom transceiver for my home automation needs, and it’s been one of the best decisions I’ve made with regards to home automation. Not only can it transmit and receive LightwaveRF signals, it can also do Byron, Nexa, X10, Oregon Scientific, and a whole tonne more.

I subsequently discovered these dirt cheap Imagintronix humidity and temperature transmitter devices, which you can buy for £7 each. The temperature sensor needs to be calibrated against a known source, and you then apply the difference to the device as it is picked up in Domoticz. It’s all rather simple, and you immediately have a source of temperature data that can be used. I took a variety of these sensors, and put one in each room, and rather quickly gained an overview of the house from within Domoticz.

Room temperatures

Next up was the desire to average out these temperatures per zone. We have a very simple heating system with only one zone, so it was a simple case of averaging all the temperatures to get one value that we can notionally call the ‘Average house temperature’

The issue here is that Domoticz can’t do that sort of simple calculation. It has a Blockly engine built in to it, but I didn’t see any way of making do simple calculations. However, there was a way around that…

I already use the mqtt.js script from http://www.domoticz.com/wiki/Setup_MQTT_support_to_connect_external_devices to publish MQTT messages from Domoticz, and Node-Red to do some other MQTT management things, so it was just a case of getting Node-Red to do the work instead, and then to JSONify it and push it back into Domoticz.

[{"id":"b75445a3.48abb8","type":"function","name":"JSONify","func":"msg.payload = '{\"idx\":46,\"svalue\":\"' + msg.payload + ';0;0\"}';\nreturn msg;","outputs":1,"x":495,"y":463,"z":"d5caab33.2a3558","wires":[["a4bce105.5b432"]]}]

Sorted, there’s now a dummy temperature sensor in Domoticz with IDX 46, and Node-Red emits a MQTT message with the appropriate JSON content for Domoticz to pick up and use with the temperature sensor.

Average temperature

Next step is to actually use that data…

ESP8266 Links

0

What with the recent buzz around the latest ESP8266 chips, I thought I should compile a list of handy links here…

The manufacturer of ESP8266 – http://espressif.com/
Manufacturer discussion forum – http://bbs.espressif.com/

Community forum – http://www.esp8266.com/
Lua based firmware – http://nodemcu.com/index_en.html
Discussion regarding MQTT on the ESP8266 – https://groups.google.com/forum/#!topic/mqtt/Uy985KUpG64
ESP8266 Github wiki – https://github.com/esp8266/esp8266-wiki/wiki
Working GCC Toolchain – https://github.com/esp8266/esp8266-wiki/wiki/Toolchain
Open source SDK – https://github.com/pfalcon/esp-open-sdk
Native DHT22 and LED I/O using Lua – http://harizanov.com/2014/11/esp8266-powered-web-server-led-control-dht22-temperaturehumidity-sensor-reading/

Buy one (UK) – http://www.amazon.co.uk/gp/product/B00O9DSZBA/?tag=thelod-21

MQTT to Zabbix Gateway

0

For a while now I’ve been wanting to try and monitor home automation parameters by using Zabbix. I already use it to monitor, graph and alert on servers and services at work and at home, so it was a logical extension to use it for home automation. I hope to deploy TinyTX sensors around the house, and by using my mqtt-rfm12b gateway I *should* be able monitor and alert on their battery voltages when things start to run a bit low. Firstly though, something is required to push the data from MQTT to Zabbix.

The first thing that you’ll need is a working Zabbix instance. This is somewhat outside the scope of this blog post, and the documentation is fairly good. You’ll need a host configured, so add one and give it a name, or alternatively use localhost that I think Zabbix comes preconfigured with.

Clone my mqtt-zabbix repository, and you’ll find a XML Zabbix template that can be imported into your Zabbix install (import via Configuration -> Templates). It won’t do anything drastic other than 10 or so Zabbix keys.

Once the import is completed, Configuration -> Templates will contain a template called “Template App MQTT”. This has the 10 items, all of which can be edited to suit. The important part is the “Key” – which must match what you put in the keys.csv later on. Simply put, when Zabbix receives data with a specific key, it gets stored against the item with that key defined. It’s not terribly complicated :-)

If you’re happy with Zabbix and the template import, follow the mqtt-zabbix README to get the rest of it installed. It’s really just a glorified script with some init scripts. Put all the files in the right places, edit keys.csv to match between your MQTT topic and your Zabbix key name, and start the application.

mqtt-zabbix subscribes to the root wildcard topic at /# so possibly isn’t very efficient on systems with massive amounts of traffic, but for home use it’s quite sufficient. I may change this method of working at a later date. In the meantime, the moment something arrives at your topic it will be forwarded on to Zabbix. A log of the event will also be found at  /var/log/mqtt-zabbix.log and it will tell you if the key was successfully inserted or not.

To view your data in Zabbix, click on the host, click on Latest Data, and it should be listed under – Other -. You can then choose the graph option on the right, or you can edit your own custom graphs and include the MQTT items.

Automated Kitchen Lighting

0

Recently I decided to make some changes to the kitchen. It started off with a strip of warm white LEDs, and I thought “Wouldn’t it be cool if…”. I’ve now lost count of the number of guests asking how it works :-)

There’s a variety of components at play here. Firstly, there’s a Raspberry Pi, followed up by a simple IRF530 MOSFET, a PNP transistor to pull it low, a PIR sensor, and a strip of LEDs.

Sensing

It’s a a PIR sensor from Seeedstudio that I bought on a whim a while back. It handily runs off of 5v, and returns a 3.3v TTL compatible signal upon detection of movement.

On the Raspberry Pi, I have my own Python app, mqtt-gpio-trigger, running. It continuously monitors pins that are defined in the config file, and in the event of a change of state of any of them it will publish a message to a predefined topic, with the pin number as the final component of the topic, and the message contains the state of the PIN. Simply subscribe to that topic to watch whatever pin on the Raspberry Pi.

Lighting

A strip of warm white LED lights are attached to pin 18 of the Raspberry Pi, via the IRF530 MOSFET. There’s a bog standard NPN transistor to help saturate the gate of the MOSFET, and it’s pin 18 as that’s the only pin on the Raspberry Pi that does hardware PWM. Using any of the other pins subjects you to vagaries of the CPU.

Controlling pin 18 is mqtt-pwm-lights, another one of my scripts. It simply sits and runs, and subscribes to yet another MQTT topic. When it receives a message with a value between 0 and 512, it fades the lights to that value. Due to the NPN transistor it’s inverted, so 512 is off, and 0 is on. A minor annoyance, but the home automation controller handles that.

In the middle

Producing the show is a small script that isn’t public. All it does is listen for MQTT events and reply with canned MQTT messages in return. It’s a stopgap measure until I find a better home automation controller. The main role of the script at the moment is to listen to events from the PIR, start a timer when triggered, and publish a lighting level request. When the timer expires, the lighting level returns to normal (ie, off)

So that’s it. Ambient automated lighting for the kitchen, and worktop lighting, all rolled into one.

Go to Top