Home Home Automation Xiaomi Aqara Temp & Humidity sensor in NodeRED

Xiaomi Aqara Temp & Humidity sensor in NodeRED

It's cold. Perfect time to mess about with my heating system

Some time ago, I made a NEST alike smart controller for my thermostat. This device used NodeRED as the platform and up until now, it has been reading the temperature from a single DHT11 sensor. I have learned that I can integrate the Xiaomi’s Gateway into NodeRED without hardware modification, so adding the Aqara Temp & Humidity sensor in NodeRED is the next step. The best thing is, these are very small and use low power! At less than $10 you could have one in each room!

Xiaomi Aqara Temp & Humidity sensor in NodeRED

To use the Aqara Temp & Humidity sensor in NodeRED you will need the Xiaomi Gateway. I have covered this already in my previous tutorial. This one builds on that knowledge, so please make sure you are familiar with the concept. 

The sensor is capable of temperature and humidity reporting in 15 min intervals. In addition to this, there is a small button which will check the connectivity (sadly in Chinese) and will send the values on request. That information can be intercepted by the gateway and posted via a debug node:
Temperature

{
	"cmd": "report",
	"model": "sensor_ht",
	"sid": "158dxxxxxx",
	"short_id": 20028,
	"data": {
		"temperature": "2152"
	}
}

Humidity

{
	"cmd": "report",
	"model": "sensor_ht",
	"sid": "158dxxxxxxx",
	"short_id": 20028,
	"data": {
		"humidity": "4801"
	}
}

The two payloads contain the information as 4 digit integer. To obtain the true value, you have to divide the value by 1000. (in examples T: 21.52°C H:48.01%) If you are interested in F rather than C – you will need to convert according to the formula:

T(°F) = T(°C) * 1.8 + 32

There is a node responsible for collecting the information from the sensor and making it available as a payload in a more readable format, however, the node is lacking conversion from C to F

Just Values

{
	"temperature": 21.54,
	"humidity": 49.17,
	"pressure": null,
	"voltage": 2.975,
	"voltage_level": "high",
	"time": 1546734980991,
	"device": "Temp1"
}

The values also contain information about the battery level which is why I’m not going to do this manually with a function node.

Full Data

{
	"cmd": "report",
	"model": "sensor_ht",
	"sid": "158d00xxxxx",
	"short_id": 20028,
	"data": {
		"temperature": "2152"
	}
}
{
	"cmd": "report",
	"model": "sensor_ht",
	"sid": "158d000xxx",
	"short_id": 20028,
	"data": {
		"humidity": "4801"
	}
}

In this mode, the sensor data is returned as it would be directly from the gateway itself.

Charts, Temperature, Humidity and conversions

To display the data in a meaningful way, I’m going to use NodeRED dashboard. It’s easy to deploy I will have no problems getting the reading this way. The chart node requires an integer payload (number) and a separate topic for each value type. I will post 3 types of values: Temperature in °C in °F and Humidity in %.

To achieve this I have to first limit the rate of incoming messages (each time I get one with temperature and one with humidity) with a limit node (limit: 1 message in 3 sec). Then I have to recalculate the temperature in F, round the values (I really don’t care about decimal points) and split the message into three payloads. I can achieve this with a function node:

var h = Math.floor(msg.payload.humidity);
var c = Math.floor(msg.payload.temperature);
var f = Math.floor(c*1.8 + 32); 
var msg1 = { payload: c };
var msg2 = { payload: f };
var msg3 = {payload: h};
   
return [msg1, msg2, msg3];

To each payload, I have to add a unique topic and I can pass the values to the chart node.

Buy Aqara Temperature & Humidity sensor

Buy it using these links to support NotEnoughTech.

Integration with NEST alike thermostat

2 sensors sharing the average temperature

Having 2 or more temperature sensors at home is beneficial. In my case, one is located upstairs (it’s warmer there) and the other is located near the entry door (the coldest area). I can now track the ambient temperature from both locations and prioritise one reading over another one.

2 sensors – thermostat will prioritise reading from one over another thanks to the switch

I don’t have heating zones implemented yet as this will require a plumbing job, which I cannot afford right now, I can use the data from the temperature sensor to stop the heating when the desired location reaches the set temperature. In the evenings, I often work in my office (upstairs) so there is no reason to heat up the house more even if the temperature downstairs reports the value below the target.

I have introduced 2 switches which with a simple help of the control flow will prioritise the reading from one temperature sensor over the other.
To make sure both values are submitted in the same object – I have copied the values with change node into the msg.payload and modified the function node to:

flow.set('TempAmbient', msg.payload);
return msg;

Conclusion

Using the Aqara Temp & Humidity sensor in NodeRED is very simple and effective. This and the fact that the sensor uses low power Zigbee protocol makes it a great portable device to monitor temperature changes across the house. The time will tell how long the sensor lasts on a single battery, but something tells me, months will pass before I have to pop the cover open to change the battery. I will be getting more sensors soon. At some point, I want to map one sensor to each room and start collecting the data. In the future, Aqara Temp & Humidity sensors will be controlling the radiators directly.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

0
Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

0
You can teach new buttons old tricks!

ESP8266 ceiling light – demo

0
Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

0
Raspberry Pi can help you with your Tasker profiles

Smart Home

Army of robots: SwitchBot Curtain

0
An army of SwitchBot Curtains - adorable CurtainBots to open and close practically any curtains!

Zemismart Roller Shade Driver

0
Frustrated with UK's roller measurements I reached out for Zemismart Roller Shade Driver

Most affordable smart lightbulbs: Sonoff B02 & B05

0
ITEAD just dropped a range of very affordable smart Sonoff lightbulbs

Creepy Alexa for Halloween

0
Turning Amazon Echo into a Creepy Alexa monster for Halloween

How to make Sonoff ZB Mini and ZigBee2MQTT work together

0
It's time to make Sonoff ZB Mini and ZigBee2MQTT work together!