Node-RED Node


#1

This topic is dedicated to comments and conversations about the following RuuviLab tutorial:

If you don’t see any comments yet, don’t be afraid to be the first one to contribute!


#2

Hello,

I’m bit confused, is there custom Node-RED node for RuuviTag available?

EDIT: Here is link for that: https://github.com/ojousima/node-red


#3

Great node! Working like a charm :+1: and I finally replace my crontab task for monitoring every 10min my RuuviTag+s placed in every room of my house :grin:

If someone is interested, here is my flow. Enjoy!

[
    {
        "id": "4a8bdd14.b8273c",
        "type": "inject",
        "z": "a0d43e19.34e2",
        "name": "Start BLE scan every 10min",
        "topic": "startBLEScan",
        "payload": "{ \"scan\": true }",
        "payloadType": "json",
        "repeat": "600",
        "crontab": "",
        "once": true,
        "x": 210,
        "y": 80,
        "wires": [
            [
                "e57b915d.d96dc"
            ]
        ]
    },
    {
        "id": "e57b915d.d96dc",
        "type": "scan ble",
        "z": "a0d43e19.34e2",
        "uuids": "",
        "duplicates": false,
        "name": "",
        "x": 590,
        "y": 120,
        "wires": [
            [
                "8065e07d.317b18"
            ]
        ]
    },
    {
        "id": "8065e07d.317b18",
        "type": "ruuvitag",
        "z": "a0d43e19.34e2",
        "name": "",
        "x": 760,
        "y": 120,
        "wires": [
            [
                "28a3f1f8.c6ddb6"
            ]
        ]
    },
    {
        "id": "6fb8c7d6.e16b18",
        "type": "inject",
        "z": "a0d43e19.34e2",
        "name": "Stop BLE scan every 10min",
        "topic": "stopBLEScan",
        "payload": "{ \"scan\": false }",
        "payloadType": "json",
        "repeat": "600",
        "crontab": "",
        "once": true,
        "x": 200,
        "y": 160,
        "wires": [
            [
                "f9c4ebfe.f3f47"
            ]
        ]
    },
    {
        "id": "3057eda0.382f72",
        "type": "debug",
        "z": "a0d43e19.34e2",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 1150,
        "y": 60,
        "wires": []
    },
    {
        "id": "f9c4ebfe.f3f47",
        "type": "delay",
        "z": "a0d43e19.34e2",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 410,
        "y": 160,
        "wires": [
            [
                "e57b915d.d96dc"
            ]
        ]
    },
    {
        "id": "28a3f1f8.c6ddb6",
        "type": "function",
        "z": "a0d43e19.34e2",
        "name": "Generate MQTT topic",
        "func": "var device = null;\n       if (msg.peripheralUuid == \"aaaaaaaaaaaa\") {\n    device = \"bedroom1\";\n} else if (msg.peripheralUuid == \"bbbbbbbbbbbb\") { \n    device = \"livingroom\";\n} else if (msg.peripheralUuid == \"cccccccccccc\") { \n    device = \"kitchen\";\n} else if (msg.peripheralUuid == \"dddddddddddd\") { \n    device = \"bathroom\";\n} else if (msg.peripheralUuid == \"eeeeeeeeeeee\") { \n    device = \"bedroom2\";\n} else if (msg.peripheralUuid == \"ffffffffffff\") {\n    device = \"bedroom3\";\n}\nmsg.topic = device + \"/measurements\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 960,
        "y": 120,
        "wires": [
            [
                "e35e99c4.f1c26",
                "3057eda0.382f72"
            ]
        ]
    },
    {
        "id": "e35e99c4.f1c26",
        "type": "mqtt out",
        "z": "a0d43e19.34e2",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "broker": "ec06f45c.253818",
        "x": 1150,
        "y": 120,
        "wires": []
    },
    {
        "id": "ec06f45c.253818",
        "type": "mqtt-broker",
        "z": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": ""
    }
]

#4

I forget to mention the RuuviTag measurements are then displayed in OpenHAB :wink:


#5

@etatto Great stuff. Thanks for sharing this!


#6

Somehow I don’t manage to get the ruuvitag node visible. I can see it as installed form manage packages, but there’s only a greyed out box and it’s not available in the palette on the left side. Any suggestions on how to proceed?


#7

This was related to “use strict” missing in the js file, which caused my node version to bail out.


#8

hi,

i cant get it worked and i got this error. any advise ?

[scan ble:62ac8d50.337474] Unable to start BLE scan. Adapter state: unauthorized

thanks


#9

@archstein Did you follow https://github.com/sandeepmistry/noble#running-without-rootsudo?


#10

Would you share how you parse the information from Node-Red in OpenHAB? By a rule?


#11

you need to set some caps for the nodejs executable like this:
setcap cap_net_raw+eip $(eval readlink -f $(which node))


#12

There is nothing to decode: the payload contains all the measurements

I’m adding a “topic” property to the “msg” object and sending it to my mqtt broker.
Hope it helps…


#13

The question was intact, how to get the data from the MQTT Topic til OpenHAB. Do you parse the string eg. like:

outdoor/measurements {“humidity”:72.5,“temperature”:-0.33,“pressure”:102729,“accelerationX”:16,“accelerationY”:-20,“accelerationZ”:1052,“battery”:3091}

in a OpenHAB rule?


#14

sorry I didn’t read it closely…
so one item file per ruuvitag:
// /etc/openhab2/items/rhus6.items

String          rhus6Measurements       "Mesures"                                                       { mqtt = "<[mqtt:rhus6/measurements:state:default]" }
DateTime        rhus6LastUpdate         "Dernière lecture [%1$td/%1$tm/%1$tY %1$tR]"    <calendar>
Number          rhus6Battery            "Batterie [%.2f V]"
Number          rhus6BatteryIcon        "Icône 'Batterie'"
Number          rhus6Humidity           "Humidité [%.2f %%]"                            <humidity>
Number          rhus6Pressure           "Pression atmosphérique [%.2f hPa]"             <pressure>
Number          rhus6Temperature        "Temperature [%.2f °C]"                         <temperature>

and one rules file per ruuvitag:
// /etc/openhab2/rules/rhus6.rules

rule "rhus6Update"
when
        Item rhus6Measurements received update
then
        rhus6LastUpdate.postUpdate(new DateTimeType())

        var String json = (rhus6Measurements.state as StringType).toString

        var Double battery = new Double(transform("JSONPATH", "$.battery", json)) / 1000
        var Double humidity = new Double(transform("JSONPATH", "$.humidity", json))
        var Double pressure = new Double(transform("JSONPATH", "$.pressure", json)) / 100
        var Double temperature = new Double(transform("JSONPATH", "$.temperature", json))

        rhus6Battery.postUpdate(battery)
        if (                   battery < 2.50) {
                rhus6BatteryIcon.postUpdate(0)
        }
        if (battery >= 2.50 && battery < 2.55) {
                rhus6BatteryIcon.postUpdate(10)
        }
        if (battery >= 2.55 && battery < 2.60) {
                rhus6BatteryIcon.postUpdate(20)
        }
        if (battery >= 2.60 && battery < 2.65) {
                rhus6BatteryIcon.postUpdate(30)
        }
        if (battery >= 2.65 && battery < 2.70) {
                rhus6BatteryIcon.postUpdate(40)
        }
        if (battery >= 2.70 && battery < 2.75) {
                rhus6BatteryIcon.postUpdate(50)
        }
        if (battery >= 2.75 && battery < 2.80) {
                rhus6BatteryIcon.postUpdate(60)
        }
        if (battery >= 2.80 && battery < 2.85) {
                rhus6BatteryIcon.postUpdate(70)
        }
        if (battery >= 2.85 && battery < 2.90) {
                rhus6BatteryIcon.postUpdate(80)
        }
        if (battery >= 2.90 && battery < 2.95) {
                rhus6BatteryIcon.postUpdate(90)
        }
        if (battery >= 2.95                  ) {
                rhus6BatteryIcon.postUpdate(100)
        }
        rhus6Humidity.postUpdate(humidity)
        rhus6Pressure.postUpdate(pressure)
        rhus6Temperature.postUpdate(temperature)
end

#16

and you need the JSONPath Transformation Add-on for the rules


#17

That was exatcly the missing part - thanks a lot.


#18

:call_me_hand: You are welcome :wink:


#19

After long long time I started from scratch and installed Node.js & Node-RED to my C.H.I.P. (Note I’m completely newbie at this, so look at least summary at the end :slight_smile: ).

Basicly the Idea came from here:

Well I have managed to set Ruuvi-node and InfluxDB to Node-RED, as noble with npm install node-red-contrib-noble. I have given that command which should allow to use BLE when not root. Well there’s still problem cause I don’t see any BT related at Node-RED like there’s at yours workflow pics.

My goal atm. is just to able to read data from RuuviTag to database, later I probably try to get those information to Thingboard, if this is usable:

Just makes me wonder if at the end I choose not to use grafana at all (I might but not sure), would it be better to use some different database, at least at thingsboard page there is:

“ThingsBoard is able to use SQL or NoSQL(Cassandra) database layer. By default, ThingsBoard uses embedded HSQLDB instance which is very convenient for evaluation or development purposes.”

That’s for installed version as said in here:

But if thing different if using IoT PaaS Demo?

Hope you can give me some pointers which would lead me to right direction. One thing I did notice when writing this and checking things I’ve made was that npm installation of noble said that first should be installed following package: libbluetooth-dev

Comparing that to this: https://github.com/sandeepmistry/noble#running-without-rootsudo

This says: bluetooth bluez libbluetooth-dev libudev-dev some of those weren’t installed but are installed now.

So the summary :

  1. Atm I don’t see BT related at Node-RED, can you help me here?
  2. Should I use different database (or can I use multible) if I first want information to thingsboard, maybe later to grafena?

#20
  1. Please see https://github.com/ojousima/node-red
  2. I’m not familiar with Thingsboard, It seems that Things board has good support fo Postgre SQL as a backend. Data can apparently be uploaded with HTTP JSON posts: https://thingsboard.io/docs/user-guide/telemetry/#device-telemetry-upload-api . I think it would be easiest to use Node-Red’s HTTP tools to upload data to Thingsboard

#21

@otso I have installed that ojousima node-red ( RuuviTag node) and I’m able to use it in Node-RED, but that easy part (installing noble with npm install node-red-contrib-noble) does add it in node_modules folder, but at Node-RED UI there’s nothing bluetooth related nodes.

So what am I doing wrong here?