Node Red -> Domoticz help with setting up transfer

Moderator: leecollings

Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

I ask for help from colleagues in setting up the NodeRed connection with Domoticz.

Currently, thanks to colleague @michal.zd from the elektroda.pl forum, I have data from the Sofar 15KTL-X inverter in NodeRed that I would like to send to domoticz and use there.

Maybe someone will be willing to spend time and help with the subject of obtaining data from NodeRed in Domoticz.
Domoticz on a shared raspberry with NodeRed.
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by habahabahaba »

My suggestion
Create an Http-in node, form a response in json format from your data inside the flow, and then take the data from Domotics using a timer script.

Or U can use "HTTP Request node" to form there API URL and send to Dz
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hi,

@habahabahaba wrote:
My suggestion
Create an Http-in node, form a response in json format from your data inside the flow, and then take the data from Domoticz using a timer script.
Unfortunately this will not work, as a HTTP In node is intended to receive data and not to transmit data to e.g. Domoticz.
See: https://cookbook.nodered.org/http/creat ... p-endpoint

@Daro1003 wrote:
I have data from the Sofar 15KTL-X inverter in NodeRed that I would like to send to domoticz and use there.
So the data is available in Node RED and has to be send to Domoticz.
I ask for help from colleagues in setting up the NodeRed connection with Domoticz.
I can give it a try, but before doing that I need to know a couple of things.
If you can answer my questions an provide the necessary data, I can create a flow.

First.

I use Node-RED version 4.0.8, which is the latest available, although 4.1 is in the pipeline.

Questions
1
Can you provide the output of the last debug node in your flow, presenting the available data, preferable as text and not as a picture?
2.
Which data would you like to send to Domoticz? All data or a specific selection?
Note: You have to create the devices yourself. MQTT AD will not be supported.
3.
What type of Domoticz sensor do you want to use (for each type of data)
4.
Do you have a MQTT server running? If not, we will use a JSON call.

This are the most important questions, but other may rise during the process.
Let me know.

Regards
Xsarax
Posts: 1
Joined: Tuesday 04 February 2025 0:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Xsarax »

Daro1003 wrote: Sunday 02 February 2025 16:25 I ask for help from colleagues in setting up the NodeRed connection with Domoticz.

Currently, thanks to colleague @michal.zd from the elektroda.pl forum, I have data from the Sofar 15KTL-X inverter in NodeRed that I would like to send to domoticz and use there.

Maybe someone will be willing to spend time and help with the subject of obtaining data from NodeRed in Domoticz.
Domoticz on a shared raspberry with NodeRed.
To send data from NodeRed to Domoticz, you can use the Domoticz HTTP API or MQTT (if you have MQTT set up in Domoticz). In NodeRed, you can use the "http request" node or MQTT output node to push the data.
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by habahabahaba »

FireWizard wrote: Monday 03 February 2025 21:17

Unfortunately this will not work, as a HTTP In node is intended to receive data and not to transmit data to e.g. Domoticz.
See: https://cookbook.nodered.org/http/creat ... p-endpoint

Regards
Of course it will work.
Http-in is just the start of idea and od course the flow have to contain function node to form data and http-response node and may be some else to transfer data between flows... I gave just the start of idea
mgugu
Posts: 218
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by mgugu »

Maybe not http-in but http-request
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

1. I am sending a screenshot of what I would like to have highlighted in Domoticz.

2. In domoticz I can create sensors, the question is which ones?

3. I would like to use the data in the energy panel and to control heaters in blockly.

4. MQTT server or is it a broker? I have a broker because in domoticz I have data from shelly, and various sensors on Tasmota.
Attachments
Zrzut ekranu 2025-02-06 213620.png
Zrzut ekranu 2025-02-06 213620.png (7.5 KiB) Viewed 3455 times
To bym chciał.png
To bym chciał.png (21.63 KiB) Viewed 3455 times
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hello @Daro1003,

You wrote:
1. I am sending a screenshot of what I would like to have highlighted in Domoticz.
That are only a few items and is rather easy to make.

I see:

P, Avg, GP and CP, but I need some extra information.

I assume, as the device is a solar-inverter, that
P represents the Power (the totally produced Power?)
Avg represents probably some Average, but the average of what? The Power?
GP stands for what (Grid Power?) and what does CP mean? (Consumed Power?)

I need to know what these payloads mean in order to configure the correct virtual hardware in Domoticz.
This has also effect on the data we will send to Domoticz by MQTT.
2. In domoticz I can create sensors, the question is which ones?
As said, that depends on the meaning of those values. What do they represent?
3. I would like to use the data in the energy panel and to control heaters in blockly.
That is not a problem, but a Domoticz configuration for the Energy Panel.
You can also control the heaters directly from Node-RED. This will give you more possibilities,as Blockly has its limitations.
4. MQTT server or is it a broker? I have a broker because in domoticz I have data from shelly, and various sensors on Tasmota.
In the past people used more often the word "broker", but today the word "server" has become more common, I think.
But you may find an answer at: https://stackoverflow.com/questions/573 ... t-a-server or
https://electronics.stackexchange.com/q ... -vs-server

Personally I use more often the word "server", but I agree with the explanations, given in those links.
So a MQTT broker and a MQTT server are the same device. You have one available and we will use that one.

If you can answer my questions, we can make the next step and create a "Function" node with the correct data to Domoticz.

Regards
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

P represents the Power (the totally produced Power?) - YES
Avg represents probably some Average, but the average of what? The Power? - YES
GP stands for what (Grid Power?) YES and what does CP mean? (Consumed Power?) - YES
average Power is not used in this case.

Everything is as you write

Unfortunately I can't use NodeRed so I'll build automation in Domoticz. By built I mean tortured.
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hello @Daro1003,
average Power is not used in this case.
Then i suggest to create a Dummy hardware (does nothing) with 3 sensors
For all 3 sensors you can create Electric (Instant + Counter).
Edit the sensors and for the Grid Power use the 'Type" : 'Usage" and "Energy read' to "Computed".
The Consumed Power can be the same.

The total produced Power should be set to "Type" "Return" and "Energy read' to "Computed".
Unfortunately I can't use NodeRed
I hope you can insert a Function node in the Node-RED flow together with a MQTT Out node.
If not, study the Node Red essentials on their web page.

Regards
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

I have NodeRed installed on a raspberry that has domoticz and I can insert some flow.

Wouldn't it be better to send each parameter in a separate Domoticz block?

I meant that I will build automation on domoticz but I need data from the inverter.
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by habahabahaba »

IMHO The simplest way out is to use functions to generate urls and send them to domoticz via the api via httprequest.

Example for node-red:

Code: Select all

[
    {
        "id": "e8b186eeed6d8d71",
        "type": "tab",
        "label": "test",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fd9f4408dc22bd21",
        "type": "http request",
        "z": "e8b186eeed6d8d71",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "query",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 790,
        "y": 220,
        "wires": [
            [
                "1b4ee2b471fc7a65"
            ]
        ]
    },
    {
        "id": "5c238b8245232ab8",
        "type": "inject",
        "z": "e8b186eeed6d8d71",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"P\":250,\"Avg\":201,\"GP\":0, \"CP\":20}",
        "payloadType": "json",
        "x": 180,
        "y": 260,
        "wires": [
            [
                "618321cdba5d4011",
                "d3b830622281f514"
            ]
        ]
    },
    {
        "id": "618321cdba5d4011",
        "type": "debug",
        "z": "e8b186eeed6d8d71",
        "name": "debug 9",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 300,
        "y": 160,
        "wires": []
    },
    {
        "id": "d3b830622281f514",
        "type": "function",
        "z": "e8b186eeed6d8d71",
        "name": "Power func",
        "func": "if (!msg.payload || typeof msg.payload.P === 'undefined') {\n    return { payload: \"Error: Power undefined\" };\n} else {\n    const power = msg.payload.P; // \n    const sensorIdx = \"108\"; // Idx of Domoticz sensor\n     \n    const apiUrl = `/json.htm?type=command&param=udevice&idx=${encodeURIComponent(sensorIdx)}&nvalue=0&svalue=${encodeURIComponent(power)}`;\n// url\nmsg.url = `http://127.0.0.1:8080${apiUrl}`;\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 220,
        "wires": [
            [
                "199de00895426b37",
                "fd9f4408dc22bd21"
            ]
        ]
    },
    {
        "id": "199de00895426b37",
        "type": "debug",
        "z": "e8b186eeed6d8d71",
        "name": "debug 10",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 120,
        "wires": []
    },
    {
        "id": "1b4ee2b471fc7a65",
        "type": "debug",
        "z": "e8b186eeed6d8d71",
        "name": "debug 11",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 920,
        "y": 120,
        "wires": []
    }
]
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hello @Daro1003,

Please find a simple flow for 3 sensors (P, CP and GP) below.

Screenshot_Sofar_Inverter.png
Screenshot_Sofar_Inverter.png (14.33 KiB) Viewed 2176 times
You can simple replace your Debug node for the "Function" node and MQTT Output node

Do the following:

Edit the "Function" node and replace in line 3, your Domoticz idx number for P.
Do the same in line 4 for GP and in line 5 for CP.

Use your own MQTT configuration.

The solution of @habahabahaba is more or less the same, except that he tests the input for a valid response.
The main difference is that he uses HTTP and I use MQTT.
As MQTT is more efficient than HTTP and you have already a MQTT broker (server) in your network,
I recommend MQTT over HTTP. But it is nice that you have a choice. It is up to you.

For HTTP versus MQTT comparison, see: https://medium.com/@flespi/http-vs-mqtt ... adde693b5f
or https://www.hivemq.com/blog/mqtt-vs-htt ... -iot-iiot/

The flow:

Code: Select all

[
    {
        "id": "9faeea04b2b50403",
        "type": "function",
        "z": "c03666d911c02a8f",
        "name": "Prepare for Domoticz",
        "func": "// Declaration of variables\n\nlet idx1 = 123;\nlet idx2 = 456;\nlet idx3 = 789;\n\nlet msg1 = {};\nlet msg2 = {};\nlet msg3 = {};\n\nmsg1.payload = { \"command\": \"udevice\", \"idx\": idx1, \"svalue\": msg.payload.P.toString() + \";0\"};\nmsg2.payload = { \"command\": \"udevice\", \"idx\": idx2, \"svalue\": msg.payload.GP.toString() + \";0\" };\nmsg3.payload = { \"command\": \"udevice\", \"idx\": idx3, \"svalue\": msg.payload.CP.toString() + \";0\" };\n\nreturn[[msg1,msg2,msg3]];",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 180,
        "wires": [
            [
                "85eb0898c7979634",
                "5b94fc5b22b41f4e"
            ]
        ]
    },
    {
        "id": "5b94fc5b22b41f4e",
        "type": "mqtt out",
        "z": "c03666d911c02a8f",
        "name": "MQTT Domoticz",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "175c3dc01f359e9d",
        "x": 710,
        "y": 180,
        "wires": []
    },
    {
        "id": "175c3dc01f359e9d",
        "type": "mqtt-broker",
        "name": "Raspberry Pi 1B",
        "broker": "192.168.10.51",
        "port": 1883,
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": 4,
        "keepalive": 60,
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

Regards
Last edited by FireWizard on Thursday 13 February 2025 16:59, edited 1 time in total.
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

Do I insert my own IDX from domoticz in these underlined places?
Attachments
Zrzut ekranu 2025-02-13 161559.png
Zrzut ekranu 2025-02-13 161559.png (15.68 KiB) Viewed 1857 times
Zrzut ekranu 2025-02-13 161108.png
Zrzut ekranu 2025-02-13 161108.png (35.1 KiB) Viewed 1857 times
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hi @Daro1003

If I look to your screenshots, I think you have tried to insert the flow into a "Function" node.

That is not the intention.

You should do it as follows:

Select and copy the Flow from the Domoticz Forum page, as you have done before.
Click "SELECT ALL" and next press CTRL-C (Copy).

Open Node-RED editor and go to the "Hamburger" menu and Select "Import" .
In the editor field , press Ctrl-V (Paste).
This will insert the complete flow in the import window.

Next press "Import'.

This will open the flow, as shown in my previous post, in its own tab, marked "Sofar 15KTL-X inverter"

Edit the "Function" node as follows:
Do the following:

Edit the "Function" node and replace in line 3, your Domoticz idx number for P.
Do the same in line 4 for GP and in line 5 for CP.

Use your own MQTT configuration.
This is how the "Function" node looks like:

Code: Select all

// Declaration of variables

let idx1 = 123;
let idx2 = 456;
let idx3 = 789;

let msg1 = {};
let msg2 = {};
let msg3 = {};

msg1.payload = { "command": "udevice", "idx": idx1, "svalue": msg.payload.P.toString() + ";0"};
msg2.payload = { "command": "udevice", "idx": idx2, "svalue": msg.payload.GP.toString() + ";0" };
msg3.payload = { "command": "udevice", "idx": idx3, "svalue": msg.payload.CP.toString() + ";0" };

return[[msg1,msg2,msg3]];
Regards
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

So I click on options and it gives me import.
In the window as in image 2 I paste what you gave and click import.
I see two node as in image 3, I click on node F and I have it as in image 3 and there I change the IDXs to my own?
Why when I click import only 2 node appear and not 5 like in your case?

And what next? I create a node as in image 4 ??
Attachments
dwa.png
dwa.png (28.99 KiB) Viewed 1600 times
trzy.png
trzy.png (44.36 KiB) Viewed 1600 times
cztery.png
cztery.png (29.3 KiB) Viewed 1600 times
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hello @Daro1003,

You only get 2 nodes, because I only sent you these 2 nodes.

If I would send my test nodes as well, this would cause more confusion.

The only thing you should do now is:

1. Edit the "Function" node, called "Prepare for Domoticz" and insert your IDX numbers, instead of 123, 456 and 789.
Leave the rest as it is.

2. Connect the input of that "Function" node, called "Prepare for Domoticz" to the output of your MQTT Output node, called "MQTT Inverter".
And what next? I create a node as in image 4 ??
Configure the Hardware in Domoticz, called MQTT Client gateway with LAN Interface.

I see you have obviously configured a MQTT Server (Broker), called "Domoticz IN".
A MQTT server is not only intended for Domoticz, but also for other applications.
It is also not only intended for IN, but is also used for data from Domoticz.
So the name "Domoticz IN" is rather confusing.

Try it this way and let us know.

Regards
Last edited by FireWizard on Monday 24 February 2025 9:14, edited 2 times in total.
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

Please help me further.

Image 1 I changed the IP address that my Raspberry has with Domoticz.

Image 2 I changed the IDX in domoticz created 3 blocks

Image 3 Domoticz MQTT

It doesn't work :( The connection is probably ok because when I change the IP address the green "connected" sign disappears
Attachments
Zrzut ekranu 2025-02-22 171128.png
Zrzut ekranu 2025-02-22 171128.png (51.52 KiB) Viewed 707 times
Zrzut ekranu 2025-02-22 172027.png
Zrzut ekranu 2025-02-22 172027.png (54.28 KiB) Viewed 707 times
MQTT Cliebnt Gatway.png
MQTT Cliebnt Gatway.png (84.55 KiB) Viewed 707 times
Daro1003
Posts: 181
Joined: Monday 14 November 2022 12:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Poland
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by Daro1003 »

Next to it in the table there is still ERROR:

If I add debug to MQTT Inverter I get the following data:
Attachments
Debug.png
Debug.png (34.77 KiB) Viewed 706 times
Zrzut ekranu 2025-02-22 171945.png
Zrzut ekranu 2025-02-22 171945.png (30.48 KiB) Viewed 707 times
User avatar
FireWizard
Posts: 1886
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Node Red -> Domoticz help with setting up transfer

Post by FireWizard »

Hi @Daro1003,

Your MQTT Setting is not complete.

Make the following setting:

Screenshot_MQTT Setting.png
Screenshot_MQTT Setting.png (43.79 KiB) Viewed 701 times
Use as topic domoticz/in and (less important) set QoS to 0 and Retain to false.

Try again and let me know.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest