HomeHome AutomationXiaomi 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

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

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Things they don’t tell you about IKEA Trådfri

0
There are things you should know about IKEA Tradfri before you make your purchase

Smart Home

SwitchBot Plug Mini has 2 issues to resolve first

0
SwitchBot Plug Mini offers great connectivity options, energy consumption monitoring and smart features - all for $11.99

Elite measurements! Sonoff POW Elite

0
The latest device from ITEAD in the Elite line up is: Sonoff POW Elite - a new take on the known formula - a single channel switch with a power monitor.

Sonoff, what were you thinking? Sonoff Cam Slim

0
Sonoff Cam Slim looks great and feels great in your hand, but what Sonoff was thinking? These limitations will make everyone angry!

Sonoff TH Elite – call me impressed?

0
ITEAD has released a new series of devices under Elite line. I received Sonoff TH Elite and here is everything you need to know about it.

I torture-tested yeedi vac 2 pro

0
I have a new smart vacuum at home - yeedi vac 2 pro with an oscillating mop - will it make the difference to my floors?