# Convert Specific Gravity to Brix

**URL:** <https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402>\
**Category:** General\
**Created:** [17 September 2023 16:00 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402 "2023-09-17T16:00:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanprel](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@ryanprel](https://discourse.nodered.org/u/ryanprel)\
**Post date:** [17 September 2023 16:00 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402/1 "2023-09-17T16:00:52Z")

</div>

I'm attempting to convert Specific Gravity to Brix coming in via a webhook from a Tilt Hydrometer. These numbers are used to monitor fermentation progress. I pulled the equation from Wikipedia and it's below but I'm trying to figure out how to use this equation in a function node. The number coming in from the webhook in specific gravity would look something like 1.07 but I'm not very familiar with how to work this into a javascript-based function. Any help available?

**SG -\> Brix Equation:**  
Brix = (((182.4601 \* SG -775.6821) \* SG +1262.7794) \* SG -669.5622)  
_(Source:_ [_http://en.wikipedia.org/wiki/Brix_](http://en.wikipedia.org/wiki/Brix)_)_  
Punching in 1.07 for SG in this equation equates to 17.055

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [17 September 2023 16:16 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402/2 "2023-09-17T16:16:38Z")

</div>

```auto
let SG =1.07
msg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622)
return msg; // 17.05478999429988

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 September 2023 16:19 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402/3 "2023-09-17T16:19:43Z")

</div>

Or if the sg is in msg.payload then replace first line with  
`let SG = msg.payload`

---

<div class="post-metadata">

**Author:** ![ryanprel](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@ryanprel](https://discourse.nodered.org/u/ryanprel)\
**Post date:** [24 September 2023 03:20 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402/4 "2023-09-24T03:20:40Z")

</div>

Thanks for the help guys. I was able to get this working and build it into my flow. This flow splits up a few of the webhook variables that can be sent and sends them to a couple of charts and a dashboard status. The converts for brix are just converting a number out to one decimal point. There's probably another way of doing it but this was easy. This is for a RAPT Pill Tilt Hydrometer converting to Brix in Node-Red. Saying this because I wasn't able to find anything while searching so hopefully someone else finds this post useful.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/9075a6796ef617234aebe9327b419e4a56c8a367.png)

```auto
    {
        "id": "68a1165390db4044",
        "type": "http in",
        "z": "15f71001.075b9",
        "name": "Pill 6",
        "url": "/pill-6",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 110,
        "y": 880,
        "wires": [
            [
                "c0c1c1db3f8069a3",
                "daaa33cb4a8fa56f"
            ]
        ]
    },
    {
        "id": "c0c1c1db3f8069a3",
        "type": "http response",
        "z": "15f71001.075b9",
        "name": "",
        "statusCode": "200",
        "headers": {},
        "x": 100,
        "y": 840,
        "wires": []
    },
    {
        "id": "daaa33cb4a8fa56f",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Name",
        "func": "msg.payload.topic_root = msg.payload.name;\n//msg.topic = msg.payload.topic_root + \"brix\";\nmsg.payload = msg.payload;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 880,
        "wires": [
            [
                "543f2d31812b55b5",
                "f0e6583a0ca0ba7e",
                "b5c416c6f714af0a"
            ]
        ]
    },
    {
        "id": "543f2d31812b55b5",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Brix Status",
        "func": "msg.topic = msg.payload.topic_root;\nlet SG = msg.payload.gravity;\nmsg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 880,
        "wires": [
            [
                "3818095ed56aa2d2"
            ]
        ]
    },
    {
        "id": "5f164a6fb52e5d8a",
        "type": "warp",
        "z": "15f71001.075b9",
        "name": "",
        "scope": [
            "4011ba66b55d0595"
        ],
        "destination": "selected",
        "x": 760,
        "y": 920,
        "wires": []
    },
    {
        "id": "f0e6583a0ca0ba7e",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Temp Status",
        "func": "msg.topic = msg.payload.topic_root + \"/temperature\";\nmsg.payload = msg.payload.temperature;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 840,
        "wires": [
            [
                "d9aa79e0045c40dc"
            ]
        ]
    },
    {
        "id": "4061154caa2df5e5",
        "type": "warp",
        "z": "15f71001.075b9",
        "name": "",
        "scope": [
            "c4ef5e08bc02bb40"
        ],
        "destination": "selected",
        "x": 760,
        "y": 840,
        "wires": []
    },
    {
        "id": "d9aa79e0045c40dc",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "F",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 840,
        "wires": [
            [
                "4061154caa2df5e5"
            ]
        ]
    },
    {
        "id": "602647d9d0f62fdd",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Status",
        "func": "var text = context.get('text')|| [];\nmsg.topic_root = \"/name\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 750,
        "y": 880,
        "wires": [
            [
                "07bb632a4e2a7dce"
            ]
        ]
    },
    {
        "id": "3818095ed56aa2d2",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "C",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 880,
        "wires": [
            [
                "602647d9d0f62fdd"
            ]
        ]
    },
    {
        "id": "b5c416c6f714af0a",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Brix Chart",
        "func": "msg.topic = msg.payload.topic_root;\nlet SG = msg.payload.gravity\nmsg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622)\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 920,
        "wires": [
            [
                "0b3057308687b275",
                "6ec634d2764ebf00"
            ]
        ]
    },
    {
        "id": "0b3057308687b275",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "C",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 920,
        "wires": [
            [
                "5f164a6fb52e5d8a"
            ]
        ]
    },
    {
        "id": "6ec634d2764ebf00",
        "type": "debug",
        "z": "15f71001.075b9",
        "name": "debug 27",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 960,
        "wires": []
    },
    {
        "id": "07bb632a4e2a7dce",
        "type": "ui_text",
        "z": "15f71001.075b9",
        "group": "29b96df2a16b9678",
        "order": 4,
        "width": 0,
        "height": 0,
        "name": "Tank-C3",
        "label": "Current Brix",
        "format": "{{msg.topic}}: {{msg.payload}} Brix",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 960,
        "y": 940,
        "wires": []
    },
    {
        "id": "29b96df2a16b9678",
        "type": "ui_group",
        "name": "Tank C3",
        "tab": "75e2c4a4bae21b23",
        "order": 15,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "75e2c4a4bae21b23",
        "type": "ui_tab",
        "name": "Controls",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 November 2023 03:21 UTC](https://discourse.nodered.org/t/convert-specific-gravity-to-brix/81402/5 "2023-11-23T03:21:22Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
