Hi!
Welcome to this forum!
Before we're going to care about the issue you reported: What do you intend to achieve with this?
The syntax to get a value from the context is
let xy = context.get("temp")
I'm not sure what happens with your code; yet you wont get values from the context at all...
thx for the fast reply. Let me introduce, Im a real beginner, so there are maybe stupid mistakes. I want to do a regulation depending on the real world values (in this case compressor speed of my heatpump) and the outgoing value should be the temp the pump should maintain. So I want to controll the compressorspeed.
so for doing calculations I have to define variables first that get the values from the context variable?
Can't answer this yes or no: The context interface is defined as context.get(name) and context.set(name, value). If you intend to use this functionality, you have to operate via this API.
You might yet do calculations as well completely independent from any access to context.
And: You're touching an interesting point here. Could you do me a favour, do the following change to your code and post the result here - which should be a warning emitted at the debug panel:
var spd_diff = 0;
// please add the following line at this position
node.warn(context);
// thank you!
if (msg.topic === 'auslasstemp') {
now I changed the code to normal variables, but now nothing works anymore. I return the "temp" variable now only for testing, normally I would like to return "steuertemp" but thats 0.
var temp = 0;
var compspd = 0;
var compspd_soll = 0;
var defrost = 0;
var setting = 0;
node.warn(context);
if (msg.topic === 'auslasstemp') {
temp = msg.payload;
} else if (msg.topic === 'compressorspeed') {
compspd = msg.payload;
} else if (msg.topic === 'abtauen') {
defrost = msg.payload;
} else if (msg.topic === 'heatpump/solldrehzahl') {
compspd_soll = msg.payload;
}
var spd_diff = compspd_soll - compspd
if (spd_diff < 100 && spd_diff < (-100)) {
setting = 0;
} else if (spd_diff >= 100 && spd_diff < 300) {
setting = 1;
} else if (spd_diff >= 300 && spd_diff < 500) {
setting = 2;
} else if (spd_diff >= 500 && spd_diff < 8000) {
setting = 3;
} else if (spd_diff <= (-100) && spd_diff > (-300)) {
setting = (-1);
} else if (spd_diff <= (-300) && spd_diff > (-500)) {
setting = (-2);
} else if (spd_diff <= (-500) && spd_diff > (-8000)) {
setting = (-3);
}
var steuertemp = ((setting + temp) * 10);
return { topic: 'steuertemp', payload: temp }
here is my output:
1.12.2023, 15:41:41node: function 12
function : (warn)
{ set: function, get: function, keys: function, global: object, flow: object }
1.12.2023, 15:41:41node: debug 19
steuertemp : msg.payload : number
32.4
1.12.2023, 15:41:41node: function 12
function : (warn)
{ set: function, get: function, keys: function, global: object, flow: object }
1.12.2023, 15:41:41node: debug 19
steuertemp : msg.payload : number
0
1.12.2023, 15:41:41node: function 12
function : (warn)
{ set: function, get: function, keys: function, global: object, flow: object }
1.12.2023, 15:41:41node: debug 19
steuertemp : msg.payload : number
0