Trying to set the target temperature of a refrigerator. Using the Miele Swagger I can set the temperature.
In Miele Swagger the command set is:
curl -X 'PUT' \
'https://api.mcs3.miele.com/v1/devices/000712266404/actions' \
-H 'accept: */*' \
-H 'Authorization: Bearer NL_XXXXX' \
-H 'Content-Type: application/json' \
-d '{
"targetTemperature": [
{
"zone": 1,
"value": 7
}
]
}'
In Node RED I'm sending:
msg.bearer=global.get("mielebearer");
msg.device="000712266404";
msg.action="targetTemperature";
msg.parameter={
"zone": 1,
"value": 7
}
return msg;
Which will not work.
When applying a simpler action I get it operational in Node-RED, for e.g the super cooling.
In Swagger:
curl -X 'PUT' \
'https://api.mcs3.miele.com/v1/devices/000712266404/actions' \
-H 'accept: */*' \
-H 'Authorization: Bearer xxx' \
-H 'Content-Type: application/json' \
-d '{
"processAction": 7
}'
In Node-RED:
msg.bearer=global.get("mielebearer");
msg.device="000712266404";
msg.action="processAction";
msg.parameter="7";
return msg
Any idea how to resolve the issue?
John
Colin
7 March 2023 10:02
2
Perhaps you need it the same as you have in the curl command
msg.parameter=[{
"zone": 1,
"value": 7
}]
@Colin This will result in "unable to process JSON"
Colin
7 March 2023 11:27
4
What node type are you sending that message to?
@Colin
The info is in the function set var
The put action is a subflow template:
In which the first function block contains the following (in which the var msg2 part seems the most important part)
let bearer = env.get("bearer");
if (bearer === "" && msg.bearer ==="") node.send({payload:"bearer missing"});
if(msg.hasOwnProperty('bearer')) bearer=msg.bearer;
let action = env.get("action");
if (action === "" && msg.action ==="") node.send({payload:"action missing"});
if(msg.hasOwnProperty('action')) action=msg.action;
let device = env.get("device");
if (device === "" && msg.device ==="") node.send({payload:"device missing"});
if(msg.hasOwnProperty('device')) device=msg.device;
let parameter = env.get("parameter");
if (parameter === "" && msg.parameter ==="") node.send({payload:"parameter missing"});
if(msg.hasOwnProperty('parameter')) parameter=msg.parameter;
var msg2;
msg2={payload: "curl -X PUT \"https:\/\/api.mcs3.miele.com\/v1\/devices\/"+device+"\/actions\" -H \"accept: *\/*\" -H \"Authorization: Bearer "+bearer+"\" -H \"Content-Type: application\/json\" -d \"{\\\""+action+"\\\":"+parameter+"}\""};
msg1=null;
return [[msg1],[msg2]];
Colin
7 March 2023 11:57
6
We need to know what is going into the Exec node, how you have configured it, and what is coming out. Connect the second output of the function node in the subflow to a new subflow output, and the exec node output to yet another subflow output. Connect those to debug nodes set to Show Complete Message, give the debug nodes names so you can identify them, and see what you get.
Also show us how you have configured the exec node.
@Colin
This is the content of the Exec node
I do not know how to connect the second output of the function node in the subflow to a new sublow output. But when I add a debug note I will get:
"curl -X PUT "https://api.mcs3.miele.com/v1/devices/000712266404/actions" -H "accept: */*" -H "Authorization: Bearer NL_XXXXX" -H "Content-Type: application/json" -d "{\"targetTemperature\":[object Object]}""
In case I do it for the simpler function the object part is correctly filled:
curl -X PUT "https://api.mcs3.miele.com/v1/devices/000712266404/actions" -H "accept: */*" -H "Authorization: Bearer NL_XXXXX" -H "Content-Type: application/json" -d "{\"processAction\":6}"
For the Exec node I get:
{"code":400,"message":"Unable to process JSON"}
Colin
7 March 2023 13:30
8
Where did you get that subflow? It is not dealing correctly with the array parameter, as you can see.
Colin
7 March 2023 13:51
10
Try this in the function node
msg2={payload: "curl -X PUT \"https:\/\/api.mcs3.miele.com\/v1\/devices\/"+device+"\/actions\" -H \"accept: *\/*\" -H \"Authorization: Bearer "+bearer+"\" -H \"Content-Type: application\/json\" -d \"{\\\""+action+"\\\":"+JSON.stringify(parameter)+"}\""};
Check that the command output by the function node looks the same as your working curl command does.
@Colin
Same error. fyi the simple function still works.
Result of function node is;
curl -X PUT "https://api.mcs3.miele.com/v1/devices/000712266404/actions" -H "accept: */*" -H "Authorization: Bearer NL_XXXXX" -H "Content-Type: application/json" -d "{\"targetTemperature\":[{"zone":1,"value":6}]}"
I do not see any reason why it should not work.
Miele Swagger (did remove space between : and 1 but still working)
curl -X 'PUT' \
'https://api.mcs3.miele.com/v1/devices/000712266404/actions' \
-H 'accept: */*' \
-H 'Authorization: Bearer NL_XXXXX' \
-H 'Content-Type: application/json' \
-d '{
"targetTemperature": [
{
"zone":1,
"value":5
}
]
}'
Colin
7 March 2023 14:33
12
John245:
Same error.
What are you seeing directly out of the exec node?
@Colin
{"code":400,"message":"Unable to process JSON"}
Colin
7 March 2023 16:01
14
Does the working simple example still work?
In the Exec node, in the Command field put echo
, so that it echos the full command, and you should be able to see that in the debug node on the output. Post a screenshot of what that looks like, for both examples.
@Colin
For the working command:
curl -X PUT https://api.mcs3.miele.com/v1/devices/000712266404/actions -H accept: */* -H Authorization: Bearer NL_xxx -H Content-Type: application/json -d {"processAction":6}
For the command under investigation:
curl -X PUT https://api.mcs3.miele.com/v1/devices/000712266404/actions -H accept: */* -H Authorization: Bearer NL_xxx -H Content-Type: application/json -d {"targetTemperature":[{zone:1,value:6}]}
Note:
By applying echo the first command will not execute the action on the device in real.
Colin
7 March 2023 16:31
16
Obviously not. I asked whether it was still working before telling it just to echo.
I trust you can see the problem. The question is why is that happening? I need to understand what is going on.
E1cid
7 March 2023 16:44
17
John245:
[{zone:1,value:6}]
Should zone and value be wrapped in quotes?
@Colin
I see the issue.
But in the set var function the quotes are there.
No idea how to obtain these additional quotes.
@E1cid
yes. But the question is why the quotes are lost
Colin
7 March 2023 17:01
20
I have modified the line to use the newer String Interpolation syntax, which is much easier to follow. Try this
msg = { payload: `curl -X PUT "https:\/\/api.mcs3.miele.com\/v1\/devices\/${device}\/actions\" -H "accept: *\/*" -H "Authorization: Bearer ${bearer}" -H \"Content-Type: application\/json\" -d '{"${action}": ${JSON.stringify(parameter)}}'` };
Keep the echo in initially and check it looks right now.