Get value of numeric input node

Hello,

I have different input fields and I want to read out the content each second.
I used the "get state" node to trigger the reading for each second together with a "function node".

With the following content this works perfect for the my "switch nodes"

var state = context.get('state') || false;
if (msg.topic == 'switch11') {
state = msg.payload;
context.set('state', state);
}
if (msg.payload == 'get state') {
return {payload: state};
}
return;

But for my "numeric input" node and also for the "dopdown" node , I could not found a corresponding solution for the content of the "function node" until now.

Bernd

This is working with the shown function content

For these two flows I cannot get the correct funtion.

Put a debug node on the outputs of the 'switch11', the 'get state', the 'ui_numeric' and the ui_dropdown' nodes and look at what msg.payload looks like coming from each one.

Next compare that with your function node to see how the function will work with that data.

Correct working switch

ui_switch sends nothing out, but content is e.g. true.
get state sends out "get state" each second
state function sends out true each second

Not working numeric input
ui_numeric sends nothing out, but content is e.g. 30
get state sends out "get state" each second
state function should send out 30 each second but I until now have not found the correct function code to have access to the numeric value

I have checked again, the switch flow is also working without the connection from switch to the funtion node.

if (msg.topic == 'switch11') {

If you did copy the function node, have you checked what is the topic you sending from ui_numeric or from ui_dropdown nodes. Cos if those are different, the function will not save new value to context.

1 Like

With the following function ( I modified the function from the working switch) content I only get false and not the numeric content.

var state = context.get('value') || false;
if (msg.topic == 'numeric') {
state = msg.payload;
context.set('value', state);
}
if (msg.payload == 'get value') {
return {payload: state};
}
return;

I was wrong, numeric have to be connected to the function-node. I tested all in an extra small flow and now it works

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