Alternative means of measuring room temperature

As much as I like the EmonTH, for me they are simply too expensive for general deployment round the house, so I have been after a cheaper alternative for a while.

I think I’ve at last found a solution.

It consists of these Xiaomi Mijia Bluetooth Hygrothermograph devices (available for around the £10 mark) with the data read using this node-red module node-red-contrib-xiaomi-ble and a PiW Zero. One advantage of these devices is they also have a display.

Whilst they are likely to not be as reliable (in reading data terms) or accurate as an EmonTH (the temperature does oscillate), they work sufficiently well to be used to manage room temperatures especially when the readings are fed through a filter.

I’m using this PiW Zero to also do some presence detection using Bluetooth and the 2 seem to sit happily alongside each other.

Of course I then publish the data through MQTT and pull it into EmonCMS :smile:

Good solution - well done for finding that!
One problem with my installation though.
I have a Raspberry Pi 3 Model B Rev 1.2 running Raspbian GNU/Linux 8 (jessie) with EMONCMS + Node.red.
My Xiamoi temperature / humidity device is paired (using bluetoothctl | scan; then pair ).
Pi shows device as paired using bluetoothctl | paired-devices.
Added “node-red-contrib-xiaomi-ble” version 1.2.3 using node-red “Manage Palette” and simple node-red flow: inject 1 minute timestamp into a Xiamoi BLE node (configured with ) which when deployed, “node-red-contrib-xiaomi-ble” node shows “searching” then (after timeout?) shows “not found” and node-red debug tab reports “Device not found among []”
Running bluetoothctl shows:

[CHG]  Device <my device number> Connected: yes
[CHG]  Device <my device number> Connected: no

continually alternating at ~5 second intervals
hciconfig shows "UP RUNNING", "RX..." and "TX ..." errors:0
Tried lots of things but still refuses to work.
Exactly the same as above on a pi-zero running “Raspbian GNU/Linux 9 (stretch)” works ok.
Any thoughts?
(sorry if this is a bit off topic)

What version of nodejs?

Ah, did you check out the docs? node-red-contrib-xiaomi-ble (node) - Node-RED

Did you follow these instructions? GitHub - noble/noble: A Node.js BLE (Bluetooth Low Energy) central module

I did not bother to pair the devices - there is no need but perhaps it does interfere?

Problem solved with…
“sudo setcap cap_net_raw+eip $(eval readlink -f which node)”
…but only when I “un-paired” the device. Seems pairing was interfering somehow.
Many thanks for your help.

1 Like

Hi Brian,

Already got one Xiaomi Mijia, but installing node-red-contrib-xiaomi-ble on the “manage Palette”, after log in again in node-red, it disappears. Can you describe step by step what you did, so i can see what i am doing wrong? Even folowing the instruction i couldn’t get it working. For what i could find now, its related to node-gyp is not compatible with something on the node-red, but i would like to know what was you procedures if you don’t mind.

Thanks
Celso

I expect if you check the logs you will find an error stating the node.

Not really. I tried to remember what I did but it was a world of fiddling that included installing a node from here (https://github.com/jrobeson/node-bluetooth-hci-socket/) - I think it depends on your nodejs version. Check out that nodes help page and delve into the dependencies as there are a number of other things you need to do to the system to make it work such as a setcap command.

A word of warning, IIRC, EmonPis disable bluetooth on a Pi so it can use the UART. Am I remembering that correctly @TrystanLea @glyn.hudson?

“A word of warning, IIRC, EmonPis disable bluetooth on a Pi so it can use the UART.”
I can confirm that. Already make that happen.

Need to see what is causing the failed node.
Thanks.

So, after spending almost a half night and an entire morning, find out the steps to install the node.

1- Assuming emonpi updated and fully working but without node-red installed:

Open terminal on SSH and do:

2- bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

3- sudo apt-get install build-essential libudev-dev

4- npm install https://github.com/jrobeson/node-bluetooth-hci-socket/#fix-builds-for-node-10

5- sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev

6- npm install noble

7-sudo setcap cap_net_raw+eip $(eval readlink -f which node)

8-sudo service nodered start

9-Go to node-red editor and on palete manager install xiaomi.

10- It may need to sed node-red auto start from boot. That, i am not sure.

All sources are this forum, with the courtesy of @borpin and other links below (those of i could find):

https://discourse.nodered.org/t/node-red-contrib-generic-ble/6418/11

https://www.npmjs.com/package/usb

https://github.com/noble/node-bluetooth-hci-socket/issues/84

https://flows.nodered.org/node/node-red-contrib-xiaomi-ble

https://github.com/noble/noble

1 Like

Yes I knew it was something like this :smile: a right PITA but they work pretty well once you get there. Two things

  1. You will notice quite a lot of jitter with the measured temperature. I run mine through a smoothing node.
  2. I have found that if you have several of them, they do read different temperatures so I add a correction factor.
  3. I run the reads sequentially through the number of sensors I have.
  4. Sometimes the data is not returned correctly. I check and amend the MQTT output accordingly (else it mucks up EmonCMS)

This is (part of) the flow I have. Output is to an MQTT node.

Node-red flow [{"id":"f02babd0.6bf298","type":"inject","z":"3aa162cb.36945e","name":"","topic":"","payload":"","payloadType":"date","repeat":"120","crontab":"","once":true,"onceDelay":"01","x":152,"y":139.5,"wires":[["ca1c1401.6354a8"]]},{"id":"ca1c1401.6354a8","type":"Xiaomi BLE","z":"3aa162cb.36945e","name":"XIA-1A","address":"4C:65:A8:D9:59:1A","scanningTimeout":"20","x":324,"y":141.5,"wires":[["8c0b19d0.0b9748","f4d6df71.ed8fa"]]},{"id":"a1dce938.34baa8","type":"Xiaomi BLE","z":"3aa162cb.36945e","name":"XIA-98","address":"4C:65:A8:D8:DE:98","scanningTimeout":"20","x":312,"y":200.5,"wires":[["c02cd3dc.363f"]]},{"id":"8c0b19d0.0b9748","type":"function","z":"3aa162cb.36945e","name":"Trigger","func":"nmsg = {};\nreturn nmsg;","outputs":1,"noerr":0,"x":152,"y":200.5,"wires":[["a1dce938.34baa8"]]},{"id":"c02cd3dc.363f","type":"function","z":"3aa162cb.36945e","name":"Room2 - Temp/Hum Corr","func":"msg.topic = msg.address // topic for smoothing function\n\nif (msg.payload.hasOwnProperty('temperature')) {\n msg.payload.temperature = msg.payload.temperature - 0.65;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":536,"y":202.5,"wires":[["a534b123.f81ae"]]},{"id":"f4d6df71.ed8fa","type":"function","z":"3aa162cb.36945e","name":"Room1 - Temp/Hum Corr","func":"msg.topic = msg.address // topic for smoothing function\n\nif (msg.payload.hasOwnProperty('temperature')) {\n msg.payload.temperature = msg.payload.temperature - 0.3;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":537,"y":142.5,"wires":[["a534b123.f81ae"]]},{"id":"a534b123.f81ae","type":"smooth","z":"3aa162cb.36945e","name":"Smooth","property":"payload.temperature","action":"mean","count":"5","round":"1","mult":"multi","x":797.5,"y":202.5,"wires":[["a223964d.ce5008"]]},{"id":"a223964d.ce5008","type":"function","z":"3aa162cb.36945e","name":"Xiaomi Data to MQTT","func":"var newmsg =[];\nvar errormsg = \"\";\nvar mqtttopic = \"emon/xiaomi\" + msg.address;\n\nif (msg.payload.hasOwnProperty('battery')) {\n newmsg.push({topic:mqtttopic + '/' + \"battery\", payload:msg.payload.battery});\n} else {\n errormsg = \"battery \"+msg.payload.hasOwnProperty('battery')+\"\\n\";\n}\n\nif (msg.payload.hasOwnProperty('temperature')) {\n newmsg.push({topic:mqtttopic + '/' + \"temperature\", payload:msg.payload.temperature});\n} else {\n errormsg = errormsg + \"temperature \"+msg.payload.hasOwnProperty('temperature')+\"\\n\";\n}\n\nif (msg.payload.hasOwnProperty('humidity')) {\n newmsg.push({topic:mqtttopic + '/' + \"humidity\", payload:msg.payload.humidity});\n} else {\n errormsg = errormsg + \"humidity \"+msg.payload.hasOwnProperty('humidity');\n} \n\nif (errormsg !== \"\"){\n errormsg = msg.address +\"\\n\" + errormsg;\n// node.warn(errormsg);\n}\n\nreturn [newmsg];","outputs":1,"noerr":0,"x":842,"y":134,"wires":[[]]}]

HTH

Thanks!

Already got it working and did blocked emoncms.
Had to reformat a new image on my SD card. Couldn’t access the emonpi.
The part of the the flow had helped me a lot on that problem.

Best regards,
Celso

I check and amend the MQTT output accordingly (else it mucks up EmonCMS)

@borpin , @glyn.hudson
I wonder if sending the data without correction to emoncms.org would have the same effect. Does emoncms.org have measures to avoid that?

I notice after a few hours of receiving data from xiaomi and resend it to emoncms on emonpi, i start to see errors, like emonpilcd stop working ( exited)or it freezes my emonpi, leaving me unable to login. Curious is i still receiving other (non xiaomi) feed values on android app.

Sorry, I don’t understand what you are asking here.

I suggest you start a new thread with some log outputs and details of the setup so we can help you investigate this.

If we receive the data from xiaomi sensor and don’t correct de data

before send it to emoncms, it mucks up EmonCMS. My english is not the best but i understood that it messes with emoncms, making some problems.

What happened to me was without correction, i start to see system frozens, sometimes i am unable to access login page or emonpi lcd freeze and can’t change it by pressing lcd buton.
Since i had SSH disabled, my solution was to change sd card by another to preserve the logs on it.
All of that started just as i start to use the xiaomi sensor.

My question is: should i send the feeds data to emoncms.org and if i do that, could exist the possibility to mess with the server or should i avoid do that? I am curently not using emoncms.org because of that.

I can’t now but i will as soon i get home.

Thanks

I would not recommend using the Xiaomi sensor on the same Pi as EmonCMS. The reading of the sensor does seem to block the network I find.

Personally, I am going to move this onto an ESP32 with ESPHome when I get the time. Currently this is all done on a separate PiZero.

Yes not very clear - apologies. If a value is not returned from the sensor, do not send anything to EmonCMS as sending NULLS can cause issues.

Hey, no apologies needed! You are spending your time helping me and my english is not the best too.

After some “changes” (downgraded node version to 8.15.1 on my node-red installation to avoid install the “Bluetooth hci fix” (npm install https://github.com/jrobeson/node-bluetooth-hci-socket/#fix-builds-for-node-10), i didn’t have any problems yet (2 days fully working).
So, that could possibly be the reason to the issues.

just want to make sure if that happens, since i will send the feeds values to my account on emoncms.org, i need to be sure that NULL won’t freeze the server, which could affect all other users.

Thanks!

No the Nulls just seem to sometimes affect the data view, not the actually running of the server. I suspect the problems with the server was caused by the reading of the sensors locally.

4 posts were split to a new topic: RAM use increases over time

Since i can no longer edit my post, i reply to it and edited the quote.

It is NodeJS you are downgrading with ‘n’ not Node-Red.

Glad it works :smile: