Hi! Please help!
How to get any object params value?
You could try...
let myValue = msg.payload.params.thermostatTemperatureSetpoint;
That should put 27 in myValue
Only integer
let myValue = msg.payload.params.thermostatTemperatureSetPoint;
msg.payload = Number(msg.payload)-10;
if (msg.payload = myValue)
{msg.payload = "on";}
else {
{msg.payload = "off"}
}
return msg;
"Invalid JSONata expression: Argument 1 of function "substring" does not match function signature"
This is google assistant response: thermostatTemperatureSetpoint: 16
Sorry - I may have got the path slightly wrong.
If you click the appropriate line in the debug node, you should be able to copy the path (that you can then use in your function node).
Here's an example.
Patch is OK:
payload.params.thermostatTemperatureSetpoint
Get array value ok: msg.payload = msg.payload[0][0].imie;
Get object params value not working
Well I suspect something else is incorrect in your coding in the function node.
You might want to take a look at line-2 as I'm not sure what msg.payload
would return.
1, get dht11 temp: [Preformatted text](http://192.168.5.240/cm?cmnd=cmnd/temp/GlobalTemp)
2, Get value: $substring(payload,14,4)
3, in function:
let myValue = msg.payload.params.thermostatTemperatureSetPoint;
msg.payload = Number(msg.payload)-10;
if (msg.payload = myValue)
{msg.payload = "on";}
else {
{msg.payload = "off"}
}
return msg;
4, google home node connect to function, (voice control)
5, debug: (google assistant response)
object
command: "action.devices.commands.ThermostatTemperatureSetpoint"
params: object
thermostatTemperatureSetpoint: 18
online: true
5, get integer valuee (18) ?????
In line 3, you seem to be assigning myValue to msg.payload
To do a comparison, you need to use === and not =
let myValue = msg.payload.params.thermostatTemperatureSetPoint;
msg.payload = Number(msg.payload)-10; // msg.payload is an object
// so Number will not work as expected
if (msg.payload = myValue) // should be == or similar
{msg.payload = "on";}
else {
{msg.payload = "off"}
}
return msg;
Well spotted. I missed that one.
Yes, I want to assign it to work with voice control
Okay, how do I get the number 18 from this ?:
Roomterm : msg.payload : Object
object
command: "action.devices.commands.ThermostatTemperatureSetpoint"
params: object
thermostatTemperatureSetpoint: 18
online: true
As @E1cid and @M-a-r-t-i-n have pointed out... in your 'test' you have used =
rather than ==
.
So you are assigning a value to msg.payoad NOT testing.
let myValue = msg.payload.params.thermostatTemperatureSetPoint;
msg.payload = Number(msg.payload)-10;
if (msg.payload == myValue)
{msg.payload = "on";}
else {
{msg.payload = "off"}
}
return msg;
"Invalid JSONata expression: Argument 1 of function "substring" does not match function signature"
Your second line is not valid.
msg.payload is an object (i.e. it contains many different parts).
So doing msg.payload = Number(msg.payload) - 10
doesn't make sense.
You will need to sort this out.
Okay, all I want is: how do I get the number 18 from this message ?:
Roomterm : msg.payload : Object
object
command: "action.devices.commands.ThermostatTemperatureSetpoint"
params: object
thermostatTemperatureSetpoint: 18
online: true
This is sent back by google assisstant when I verbally set the temperature
The error is a JSONata error not a function node error, please post all relevant nodes and a copy of incoming payload. If you click the error node id in the debug it should take you to the node throwing the error.
No mistake !!!!
- you should use
==
(=comparison) not=
(=assignment) - this will never test positive as you are overwriting msg.payload
Can you explain what you are trying to accomplish ?
Okay, all I want is: how do I get the number 18 from this message ?:
Roomterm : msg.payload : Object
object
command: "action.devices.commands.ThermostatTemperatureSetpoint"
params: object
thermostatTemperatureSetpoint: 18
online: true
This is sent back by google assisstant when I verbally set the temperature
See the first answer from @dynamicdave
The question is: what you want to do with that value ?