Controlling light from javascript function in NodeRed

Hello,
I have really been struggling with Nodered. My flows always seem to end up in a bit of a mess.

I am trying to write a function that can set the attributes of a bulb, plus would also allow me to turn it on or off.

How do I do this? I am using a simple inject node to start the process, and a ‘call sensor’ node within nodered for the bulb. The important configuration is below.

What am I doing wrong? I think there is quite a bit. I have spend hours and hours, and sometimes I think that asking for a bit of help is appropriate.

Many thanks, and keep safe in these strange times,

George

Have the msg.payload object also contain the domain and service objects.

msg.payload = { "domain": "light", "service": "turn_on", "data": {"entity_id":"light.kitchen"}};
return msg;

Also, You don’t need to set the domain or entity_id in the Service Call node if you are setting it in the function already. One or the other is fine.

Thank you. This was perfect and just what I needed.