# ioBroker Datapoints Read / Write in a function-Node in javascript How to do?

**URL:** <https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500>\
**Category:** General\
**Tags:** node-red-dashboard, database, function-node\
**Created:** [17 March 2024 21:41 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500 "2024-03-17T21:41:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torsten02](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Torsten02](https://discourse.nodered.org/u/Torsten02)\
**Post date:** [17 March 2024 21:41 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/1 "2024-03-17T21:41:13Z")

</div>

Hello,  
all attempts to read or write the data points from the ioBroker within a function node have failed so far.  
The "Node ioBroker IN/OUT" works of course but the same in a "function Node" in javascript does not work by any way.  
Googling doesn't help either.

Can someone please post simple examples ? 😀

---

<div class="post-metadata">

**Author:** ![Torsten02](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Torsten02](https://discourse.nodered.org/u/Torsten02)\
**Post date:** [18 March 2024 13:35 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/2 "2024-03-18T13:35:19Z")

</div>

More details:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b81eeee26b64b16ad8f15c165ab3b7d3bcc35f2a.png)

I use this javascript in the **function Node** without success 🙂

`//var data = { payload : javascript.0.Rollladen\_OG.Rolllade\_OG1};

//var data = parseInt(data, 16)

//var data = getState('javascript.0.Rollladen\_OG.Rolllade\_OG1').val;

//var data = get('javascript.0.Rollladen\_OG.Rolllade\_OG1').val;

//var data = get(javascript.0.Rollladen\_OG.Rolllade\_OG1, );

//var ioBroker = global.get('ioBroker');

//var data = global.get('javascript.0.Rollladen\_OG.Rolllade\_OG1');

//var data = iobroker.get("javascript.0.Rollladen\_OG.Rolllade\_OG1").val;

**var data = global.get("javascript.0.Rollladen\_OG.Rolllade\_OG1");**

**msg.payload = data;**

**return msg;**  
`

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [20 March 2024 06:32 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/3 "2024-03-20T06:32:48Z")

</div>

Before you can get data from context (global.get) it has to be there. How are you saving that data to context? With your code it looks as if you try to get the content of the topic from another unrelated message? To get that using the context, you first have to save it there. Another way is to feed that message to a function node, eventually using a change node (set msg,payload to msg.topic) or simply do that with code inside the function node

Instead of bringing up unclear code and incomplete examples, better describe with reasonable description what you would like to achieve

---

<div class="post-metadata">

**Author:** ![Torsten02](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Torsten02](https://discourse.nodered.org/u/Torsten02)\
**Post date:** [20 March 2024 15:40 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/4 "2024-03-20T15:40:57Z")

</div>

> [@Torsten02](#):
>
> "javascript.0.Rollladen\_OG.Rolllade\_OG1"

Hallo krambriw,  
My problem is to read an existing iobroker data-point within the "function-Node" using javascript.  
Unfortunately, "getState" - command is not available in the function-Node.  
I just want to read the value. The topic is "javascript.0.Rollladen\_OG.Rolllade\_OG1" and the readout works fine with the Node "ioBroker get".  
Bur only in the function-Node manually read the value is not possible... ( for me )  
I need only the simple javascript. I hope it is easy for a profi. I´m a beginner, sorry.  
Thank´s a lot krambriw !!!

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [20 March 2024 16:44 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/5 "2024-03-20T16:44:38Z")

</div>

Unfortunately it is most likely much more needed if you want that. The node might use some software libraries, api's, protocols or other kind of methods to communicate with the iobroker

One way to find out is to study the javascript code of the iobroker node you are talking about and have installed. You should find the node in the .node-red/node\_modules directory. There you should also find the folder for the node. Inside you should have a .js file that can be studied to understand how it works. With this knowledge it should then be possible to write code in a function code doing what you are looking for but that is not done during a short coffe break

_EDIT: you could also look for alternative ways to communicate with ioBroker, like MQTT_

---

<div class="post-metadata">

**Author:** ![Torsten02](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Torsten02](https://discourse.nodered.org/u/Torsten02)\
**Post date:** [2 April 2024 20:54 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/6 "2024-04-02T20:54:23Z")

</div>

The javascript-Code of this "Node - iobroker\_ get" is there: [ioBroker.node-red/nodes/ioBroker.js at master · ioBroker/ioBroker.node-red · GitHub](https://github.com/ioBroker/ioBroker.node-red/blob/master/nodes/ioBroker.js#L361)  
But I can not reduce this code for a simple use like the following example:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/74111c8da9ae5ddce9fb7b594928460d8fc9f7e5.jpeg)

Is anyone able to write the desired software extract? Thanks!

---

<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:** [1 July 2024 20:55 UTC](https://discourse.nodered.org/t/iobroker-datapoints-read-write-in-a-function-node-in-javascript-how-to-do/86500/7 "2024-07-01T20:55:21Z")

</div>

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