What am I doing wrong here as it doesn't reset if I send {"state":"off"} as msg payload ?
I'd guess you need a json node to convert the object to a string.
Maybe need single quotes around key and value in the Then send box too.
It doesn't appear to accept single quotes. Stringifying the payload didn't help either.
Simple flow if someone can help
[{"id":"56ed77703814555a","type":"trigger","z":"be14baae.1728","name":"Off in 10 seconds","op1":"","op2":"{\"state\":\"off\"}","op1type":"nul","op2type":"json","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"{\"state\":\"off\"}","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":3370,"wires":[["8f3f0fd2507d4503"]]},{"id":"219099257e12f838","type":"inject","z":"be14baae.1728","name":"reset via payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\":\"off\"}","payloadType":"json","x":450,"y":3340,"wires":[["56ed77703814555a"]]},{"id":"81f7a5ce4d91df35","type":"inject","z":"be14baae.1728","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":440,"y":3390,"wires":[["56ed77703814555a"]]},{"id":"8f3f0fd2507d4503","type":"debug","z":"be14baae.1728","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":3370,"wires":[]}]
Using a json node works for me with you example data injects.
You can use a change node prior with a ternary expression to create msg.reset. If you omit the :
section of the ternary, then msg.reset will not be created if the expression is false.
e.g.
[{"id":"219099257e12f838","type":"inject","z":"613df62afc8a16bf","name":"reset via payload","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\":\"off\"}","payloadType":"json","x":160,"y":110,"wires":[["b65866af86638874"]]},{"id":"b65866af86638874","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"$$.payload.state = \"off\" ? true","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":140,"wires":[["56ed77703814555a"]]},{"id":"81f7a5ce4d91df35","type":"inject","z":"613df62afc8a16bf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":160,"wires":[["b65866af86638874"]]},{"id":"56ed77703814555a","type":"trigger","z":"613df62afc8a16bf","name":"Off in 10 seconds","op1":"","op2":"{\"state\":\"off\"}","op1type":"nul","op2type":"json","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"{\"state\":\"off\"}","bytopic":"all","topic":"topic","outputs":1,"x":510,"y":140,"wires":[["8f3f0fd2507d4503"]]},{"id":"8f3f0fd2507d4503","type":"debug","z":"613df62afc8a16bf","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":140,"wires":[]}]
Thanks yeah that works, but adds an extra node.
I take it that the trigger reset payload cannot be an object then ?
Does that seem like a bug / omission with the trigger node, as I couldn't see anything to suggest that an object is not permissible.
Damn those extra nodes.
At a guess, I think it only works on primitive data types.
It does seem reasonable that you should be able to test eg if msg.payload.status === "off"
I'm guessing that setting up the comparison of Objects (of any sort) is a whole new ball-game as you cannot just compare with ===
.
It is all a matter of considering what are the most important enhancements to node-red that the very limited resource available should work on.