Extract Mobile Alerts data (Technoline IoT sensors)

Small flow to extract mobile-alerts sensor data from the Web page http://measurements.mobile-alerts.eu/ using css selectors and store it into a JSON that can be handled by Node RED to ease integration into an IoT solution. Implementation currently covers time, temperature and humidity. It can easily be extended to cover other sensor types by modifying the "Build climate json from array" Node.

Necessary customizations:

  • In the "get Website HTML" Node replace xxxxxxxxxx in the URL with your Phone ID from the Mobile-Alerts App
  • In the "Build climate json from array" Node set the tag variable to your sensor name
  • if your language is not German, you need to modify the tag variables to the keywords in your language as well

Results for the sensor defined in "tag" are stored in msg.payload: msg.payload.name, msg.payload.time, msg.payload.temperature, msg.payload.humidity

The flow works as of 2017-07-20. In case the Web site is changed it probably needs to be adapted.

[
    {
        "id": "75ac2a23.6a4cb4",
        "type": "tab",
        "label": "Mobile Alerts"
    },
    {
        "id": "7ec6d149.d6ef48",
        "type": "http request",
        "z": "75ac2a23.6a4cb4",
        "name": "get Website HTML",
        "method": "GET",
        "ret": "txt",
        "url": "http://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=xxxxxxxxxxxx",
        "tls": "",
        "x": 338.5,
        "y": 205,
        "wires": [
            [
                "7f762f36.e36dc8"
            ]
        ]
    },
    {
        "id": "d7dc7cfa.bbdca8",
        "type": "inject",
        "z": "75ac2a23.6a4cb4",
        "name": "",
        "topic": "inject",
        "payload": "inject",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 118,
        "y": 205,
        "wires": [
            [
                "7ec6d149.d6ef48"
            ]
        ]
    },
    {
        "id": "7f762f36.e36dc8",
        "type": "html",
        "z": "75ac2a23.6a4cb4",
        "name": "extract array of sensor-headers and components",
        "tag": ".sensor-header > h3, .sensor-component",
        "ret": "html",
        "as": "single",
        "x": 683.5,
        "y": 205,
        "wires": [
            [
                "25a8e69b.5bed62",
                "be7a80cd.155298"
            ]
        ]
    },
    {
        "id": "25a8e69b.5bed62",
        "type": "debug",
        "z": "75ac2a23.6a4cb4",
        "name": "html parsed",
        "active": false,
        "console": "false",
        "complete": "payload",
        "x": 986.5,
        "y": 293,
        "wires": []
    },
    {
        "id": "be7a80cd.155298",
        "type": "function",
        "z": "75ac2a23.6a4cb4",
        "name": "Build climate json from array",
        "func": "    // enter your Sensor name here\n    var tag = \"mySensorname\";\n    \n    // language dependent tags of different sensors\n    var timetag = \"Zeitpunkt\";\n    var temptag = \"Temperatur\";\n    var humidtag = \"Luftfeuchtigkeit\";\n    \n    // temporary variables and objects\n    var temp = msg.payload;\n    var found = 0;\n    newPayload = {};\n    \n    // go through array\n    // if sensorname is found then\n    // assign values surrounded by <h4> to JSON\n    for (var i=0; i<temp.length; i++) {\n      if(temp[i].indexOf(tag) > -1) {\n          found = 1;\n          newPayload.name = tag;\n          i++;\n        }\n      if(temp[i].indexOf(\"<a href\") > -1) {\n          found = 0;\n        }\n      if (found) {\n          if (temp[i].indexOf(timetag) > -1) {\n             var start = temp[i].indexOf(\"<h4>\") + 4;\n             var end = temp[i].indexOf(\"</h4>\") - start;\n             newPayload.time = temp[i].substr(start, end);\n\t\t  }\t \n          if (temp[i].indexOf(temptag) > -1) {\n             var start = temp[i].indexOf(\"<h4>\") + 4;\n             var end = temp[i].indexOf(\"</h4>\") - start - 2;\n             newPayload.temperature = temp[i].substr(start, end);\n\t\t  } \n\t\t  if (temp[i].indexOf(humidtag) > -1) {\n             var start = temp[i].indexOf(\"<h4>\") + 4;\n             var end = temp[i].indexOf(\"</h4>\") - start;\n             newPayload.humidity = temp[i].substr(start, end);\n          }\n        }\n    }\n    msg.payload = newPayload;\n    return msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1085.5,
        "y": 205,
        "wires": [
            [
                "4de4111c.2adb68"
            ]
        ]
    },
    {
        "id": "4de4111c.2adb68",
        "type": "debug",
        "z": "75ac2a23.6a4cb4",
        "name": "json",
        "active": true,
        "console": "false",
        "complete": "payload",
        "x": 1316.5,
        "y": 205,
        "wires": []
    }
]
tskalla

Flow Info

created 1 month ago

Node Types

Core
  • debug (x2)
  • function (x1)
  • html (x1)
  • http request (x1)
  • inject (x1)
Other
  • tab (x1)

Tags

  • iot
  • mobile-alerts
  • sensors
  • temperature
  • humidity
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option