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

Sonoff R3 DIY mode & why it sucks

0
Long awaited Sonoff R3 DIY mode is even worse than I expected.

IKEA TRADFRI Wireless dimmer in NodeRED

0
Thanks to NodeRED you can use IKEA TRADFRI Wireless Dimmer to interact with everything

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

Flashing Tasmota on Sonoff ZigBee Bridge

0
How to flash Tasmota on Sonoff ZigBee Bridge to enable it for NodeRED and Home Assistant

Flashing ESP with Tasmotizer is a dream come true

0
How to flash Tasmota on ESP devices with new Tasmotizer tool

Smart Home

How to use Aqara T1 with ZigBee2MQTT

0
Learn how to add Aqara T1 and other in wall relays to NodeRED and build an awesome dashboard that comes with power consumption data that works for all relays.

One switch for all your needs? Shelly 1L

0
Shelly 1L can be installed in no--neutral and live and neutral configurations. Check out what else it brings to the table

Is Aqara T1 ZigBee switch all I asked for?

0
Aqara introduces 2 new switches Aqara T1 ZigBee switch in no-neutral and L & N configurations

No more hubs: Aqara G2H

0
Aqara G2H brings the power of ZigBee sensors to an IP camera.

Two cool features of Avatar Smart Bulbs

0
Avatar Smart Bulbs come with 2 cool features I wish more smart bulb manufacturers would include in their products.