convert true/false to 1/0

646 views
Skip to first unread message

Christophe L

unread,
Dec 9, 2017, 12:05:46 PM12/9/17
to Node-RED

Hello.
I start with node red, I use it to monitor a pellet boiler.
node red for the reading part of the data, influxdb for the recording and grafana for the visualization.
it works rather well, I have a problem with the data type boolean (true and false).
I can not use this data with grafana. I try to convert them with node red but without success.

Do you have an idea

my clipboard
[{"id":"72f19347.39e44c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5f7b8425.49d45c","type":"inject","z":"72f19347.39e44c","name":"Get every 15s","topic":"","payload":"","payloadType":"date","repeat":"15","crontab":"","once":false,"x":125.66668701171875,"y":82.16667175292969,"wires":[["cad562e2.b4dc18","a8b6f159.c6fdc","a9339ca1.396608"]]},{"id":"40972898.32e0f8","type":"debug","z":"72f19347.39e44c","name":"","active":true,"console":"false","complete":"payload","x":898.1666870117188,"y":20,"wires":[]},{"id":"a9339ca1.396608","type":"modbus-getter","z":"72f19347.39e44c","name":"getter fc01","showStatusActivities":true,"showErrors":true,"unitid":"1","dataType":"Coil","adr":"0","quantity":"140","server":"9a82ea6f.d0474","x":323,"y":133,"wires":[[],["5f8e0823.ab1fe","78f2b3dc.6f64cc","87c5001d.962c58"]]},{"id":"5f8e0823.ab1fe","type":"modbus-response","z":"72f19347.39e44c","name":"","registerShowMax":"150","x":364,"y":197.66671752929688,"wires":[]},{"id":"cad562e2.b4dc18","type":"modbus-getter","z":"72f19347.39e44c","name":"getter fc04","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"InputRegister","adr":"0","quantity":"125","server":"9a82ea6f.d0474","x":281,"y":267,"wires":[[],["3a8faace.e86016"]]},{"id":"a8b6f159.c6fdc","type":"modbus-getter","z":"72f19347.39e44c","name":"","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"InputRegister","adr":"4000","quantity":"2","server":"9a82ea6f.d0474","x":285,"y":316.5,"wires":[[],["abc88698.272f68"]]},{"id":"d1d0fbc3.ef64b","type":"influxdb batch","z":"72f19347.39e44c","influxdb":"6a64ac0.f08ca54","precision":"","retentionPolicy":"","name":"actuel value","x":722.0000610351562,"y":275.8333435058594,"wires":[]},{"id":"3a8faace.e86016","type":"function","z":"72f19347.39e44c","name":"Froling to influxdb","func":"msg.payload = [\n    {\n        measurement: \"actuel_value\",\n        fields: {\n            Tp4: msg.payload.data[0]/2,\n            Tgaz: msg.payload.data[1]/2,\n            O2r: msg.payload.data[3]/10,\n            Tex: msg.payload.data[4]/2,\n            fan_speed: msg.payload.data[7],\n            air_speedin: msg.payload.data[12]/100,\n            fan_control: msg.payload.data[15],\n            Tboilier_set: msg.payload.data[18],\n            Tgaz_set: msg.payload.data[19],\n            Thk1: msg.payload.data[21]/2,\n            Thk1_set: msg.payload.data[22]/2,\n            Thk2: msg.payload.data[25]/2,\n            Thk2_set: msg.payload.data[26]/2,\n            Tdhw_top: msg.payload.data[93]/2,\n            Tdhw_bottom: msg.payload.data[94]/2,\n            Tair_in: msg.payload.data[96]/2,\n            Feed: msg.payload.data[116],\n            O2_set: msg.payload.data[117],\n            //Boilier_set: msg.payload.data[138]/2,\n            //Dhw_pump: msg.payload.data[144],\n            //Feed_hours: msg.payload.data[174],\n            \n        },\n        tags:{\n            location:\"froling\"\n        },\n        timestamp: new Date()\n    }\n   \n];\nreturn msg;","outputs":"1","noerr":0,"x":495.16668701171875,"y":274.6666564941406,"wires":[["d1d0fbc3.ef64b"]],"inputLabels":["modbus getter"],"outputLabels":["influx batch"]},{"id":"abc88698.272f68","type":"function","z":"72f19347.39e44c","name":"Froling to influxdb","func":"msg.payload = [\n    {\n        measurement: \"actuel_value\",\n        fields: {\n            sys_state: msg.payload.data[0],\n            P4_state: msg.payload.data[1],\n        },\n        tags:{\n            location:\"froling\"\n        },\n        timestamp: new Date()\n    }\n   \n];\nreturn msg;","outputs":"1","noerr":0,"x":492.16668701171875,"y":322.1666564941406,"wires":[["f44ddc56.77f73"]],"inputLabels":["modbus getter"],"outputLabels":["influx batch"]},{"id":"f44ddc56.77f73","type":"influxdb batch","z":"72f19347.39e44c","influxdb":"6a64ac0.f08ca54","precision":"","retentionPolicy":"","name":"acv states","x":723.1666870117188,"y":320.1666564941406,"wires":[]},{"id":"87c5001d.962c58","type":"function","z":"72f19347.39e44c","name":"Froling to influxdb","func":"msg.payload = [\n    {\n        measurement: \"digital_ouput\",\n        fields: {\n            hk1: msg.payload.data[0],\n            hk2: msg.payload.data[1],\n        },\n        tags:{\n            location:\"froling\"\n        },\n        timestamp: new Date()\n    }\n   \n];\nreturn msg;","outputs":"1","noerr":0,"x":594.1666870117188,"y":142.16665649414062,"wires":[["40972898.32e0f8"]],"inputLabels":["modbus getter"],"outputLabels":["influx batch"]},{"id":"f73d6a4f.2486e8","type":"influxdb batch","z":"72f19347.39e44c","influxdb":"6a64ac0.f08ca54","precision":"","retentionPolicy":"","name":"digital output","x":945.1666870117188,"y":78.16666412353516,"wires":[]},{"id":"78f2b3dc.6f64cc","type":"change","z":"72f19347.39e44c","name":"bool to nbs","rules":[{"t":"change","p":"payload.Object","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload.Object","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":607,"y":32.50000762939453,"wires":[[]]},{"id":"73f5b0fe.fe1fa8","type":"rpi-gpio in","z":"72f19347.39e44c","name":"PIR pellet","pin":"11","intype":"down","debounce":"500","read":false,"x":103.16667175292969,"y":28.166664123535156,"wires":[["a30cb172.7f508"]]},{"id":"a30cb172.7f508","type":"change","z":"72f19347.39e44c","name":"Tours->kgs","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"0.024","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":329.1666717529297,"y":30.166656494140625,"wires":[[]]},{"id":"9a82ea6f.d0474","type":"modbus-client","z":"","name":"Froling","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"57600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":670,"reconnectTimeout":2000},{"id":"6a64ac0.f08ca54","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"froling","name":"froling","usetls":false,"tls":""}]



Colin Law

unread,
Dec 9, 2017, 12:27:08 PM12/9/17
to node...@googlegroups.com
I cannot deploy your flow as it needs several special nodes installed (modubus etc). However to convert from true/false to 1/0 you can use a Change node configured to Change msg.payload to the JSONata expression:

payload ? 1 : 0

as in this test flow

[
    {
        "id": "f69ec197.7010f",
        "type": "debug",
        "z": "f0414dd0.dd514",
        "name": "Result",

        "active": true,
        "console": "false",
        "complete": "payload",
        "x": 692,
        "y": 88,
        "wires": []
    },
    {
        "id": "8e686354.2d7da",
        "type": "change",
        "z": "f0414dd0.dd514",
        "name": "",
        "rules": [
            {
                "t": "set",

                "p": "payload",
                "pt": "msg",
                "to": "payload ? 1 : 0",
                "tot": "jsonata"

            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 464,
        "y": 87,
        "wires": [
            [
                "f69ec197.7010f"
            ]
        ]
    },
    {
        "id": "9fcfa1ed.4926e8",
        "type": "inject",
        "z": "f0414dd0.dd514",
        "name": "",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 232,
        "y": 37,
        "wires": [
            [
                "8e686354.2d7da"
            ]
        ]
    },
    {
        "id": "a54d2a3b.5de948",
        "type": "inject",
        "z": "f0414dd0.dd514",
        "name": "",
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 232,
        "y": 83,
        "wires": [
            [
                "8e686354.2d7da"
            ]
        ]
    }
]

Colin


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/414f2a58-69ae-4c8d-bf64-afcef3619315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages