Setting new payload issue

Hi,

I'm trying to set a new payload through a function when the percentage gets low, so I can send a notification to IFTTT.

Here is what my function contains:

foodlevel = msg.payload

if (foodlevel <= 30) {
    msg.payload.value1 = "Your cat is running low on food";
    return [ msg, null ];
}
else {
    msg.payload = false;
    return [ null, msg ];
}
return msg;

Now, if I set msg.payload.value1 straight in an injection node, it works fine. But not in this function node. Let's say I inject 15 and but a debug node at the end, I only receive the msg.payload value

Any ideas?

Thanks!!

[{"id":"a22e2c6e.5ba37","type":"debug","z":"c9e47736.9ab4f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1670,"y":320,"wires":[]},{"id":"cba8a09d.58781","type":"inject","z":"c9e47736.9ab4f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":1350,"y":300,"wires":[["f2aa95ba.76dc78"]]},{"id":"f2aa95ba.76dc78","type":"function","z":"c9e47736.9ab4f8","name":"<= 30","func":"foodlevel = msg.payload\n\nif (foodlevel <= 30) {\n    msg.payload.value1 = \"Your cat is running low on food\";\n    return [ msg, null ];\n}\nelse {\n    msg.payload = false;\n    return [ null, msg ];\n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":260,"wires":[["a22e2c6e.5ba37","9d571b70.71cdd8"],[]]},{"id":"9d571b70.71cdd8","type":"ifttt out","z":"c9e47736.9ab4f8","eventName":"app_notification","key":"9cab39fb.96f3a8","x":1700,"y":260,"wires":[]},{"id":"408519d4.3ca988","type":"inject","z":"c9e47736.9ab4f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":1350,"y":260,"wires":[["f2aa95ba.76dc78"]]},{"id":"9cab39fb.96f3a8","type":"ifttt-key"}]

If payload is not an object you cannot add a property .value1

You can set payload to an object with a value1 prop like this...
msg.payload = { value1: "Your cat is running low on food" };

Perfect i'll do it that way then. I was trying to follow the node's instruction:

ifttt out
Publishes msg.payload.value1, 2 and 3 to the
Maker channel in IFTTT in the specified channel.

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