Please help with calling event with payload in inject node in node-red

For the life of me I cannot call service with function node. Can someone please explain basics how to send payload from inject/function to event node?

I managed to get a working example by filling the Data attributes inside event node. I can activate this node by using timestamp injection or switch node which triggers event based on VOC level readings: Imgur: The magic of the Internet

As first step I have created two identical event nodes with different profiles which are being called based on the VOC sensor reading levels. VOC levels which are over threshold calls {“preset_mode”: “Boost”} and below threshold {“preset_mode”: “Home”} is being called.

For the next step, I would like to use function node which would send preset_mode via payload. This would give more flexibility to build custom logic with more sensors which would trigger the preset_mode accordingly.

Prior writing code for function node, I tried to inject msg.payload {“preset_mode”: “Boost”}. The event node is the same as in example above, but with empty “Data” field. I was hoping the msg.payload will fill this field and trigger an event with payload value.

Instead, Im getting errors. Please see screenshot with debug information included: Imgur: The magic of the Internet

Can someone please help to understand why event node wont accept the payload from inject node?

Thank you very much!

Use

{  "preset_mode": payload  }

Sorry, I’m little confused. I am using preset_mode they way you are advising, I have added preset_mode inside inject node:

This

image

Should be { "preset_mode": payload }

I am receiving same error when changing inject node per your example. Please note i’m trying to inject payload inside event node with empty Data value. Essentially I want event node to use payload which it would receive from inject node. So the “Boost” and “Home” values should be delivered from somewhere.

I’m trying to inject value in node which is configured as such:

This should not be blank

image

Use { "preset_mode": payload }

payload will be replaced by the value of msg.payload when it is triggered.

1 Like

Perfect, this fixed the issue. Thank you so much.

1 Like

That link I posted all the examples, they can be imported to your workspace. The top right side hamburger menu choose import and you can see all the different flows available.