Problem with calendar input to Home assistant

When i create a flow and send the data as a msg to a create calendar event i got this error : InputError: Invalid JSON: {“[object Object]”}
When i put the (captured data directly in the data field it works. What am i doing wrong.
I try to export the flow and hope i insert it right.
I USE Node-RED V 4.0.9

[{"id":"ecfe3752ca47f229","type":"api-call-service","z":"7feba46b9875e560","name":"Create Calendar Event","server":"918a63e0.1bc5a","version":7,"debugenabled":false,"action":"calendar.create_event","floorId":[],"areaId":[],"deviceId":[],"entityId":["calendar.electricity"],"labelId":[],"data":"{\"summary\":\"AUTO LADEN\",\"description\":\"AUTO LADEN\",\"start_date_time\":\"2025-03-01 12:12:00\",\"end_date_time\":\"2025-03-01 13:12:00\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","blockInputOverrides":false,"domain":"calendar","service":"create_event","x":780,"y":4620,"wires":[[]]},{"id":"0516f056dabf6ece","type":"inject","z":"7feba46b9875e560","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":4620,"wires":[["ecfe3752ca47f229"]]},{"id":"97e76ca760ce6e66","type":"function","z":"7feba46b9875e560","name":"Create Event Data","func":"let startdatum = flow.get('startdate');\nlet einddatum =  flow.get('enddate');\n\n\n\nvar msg2 = {\n    sum: \"AUTO LADEN\",\n    des: \"AUTO LADEN\",\n    sta: startdatum,\n    end: einddatum\n};\n\nvar msg4 = { payload: msg2 }\nmsg.payload = msg4.payload;\nreturn[msg.payload];","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":4480,"wires":[["5daeb51b0b6f3f60","aca92fef589d791c"]]},{"id":"20835c8456ab0ce2","type":"inject","z":"7feba46b9875e560","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":4480,"wires":[["97e76ca760ce6e66"]]},{"id":"5daeb51b0b6f3f60","type":"api-call-service","z":"7feba46b9875e560","name":"Create Calendar Event","server":"918a63e0.1bc5a","version":7,"debugenabled":false,"action":"calendar.create_event","floorId":[],"areaId":[],"deviceId":[],"entityId":["calendar.electricity"],"labelId":[],"data":"{{payload}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","blockInputOverrides":false,"domain":"calendar","service":"create_event","x":780,"y":4480,"wires":[[]]},{"id":"aca92fef589d791c","type":"debug","z":"7feba46b9875e560","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":4540,"wires":[]},{"id":"918a63e0.1bc5a","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

You have the wrong sort of quotes in your exported flow. Did you go via a text editor or something similar. You just need to select the nodes, click CTRL+E (or Export via the menu), select Copy to Clipboard, then paste it into your reply between tripple backticks (which must be on separate lines).

Before doing the export again, add another debug node showing what is going into the lower calendar node, and compare it carefully with what is going into the upper one, there must be a difference.

Hope this is the correct way to do it :slight_smile: the extra debug node is not addad. the data is 'hard coded'

Your function is the issue:

let startdatum = flow.get('startdate');
let einddatum =  flow.get('enddate');



var msg2 = {
    sum: "AUTO LADEN",
    des: "AUTO LADEN",
    sta: startdatum,
    end: einddatum
};

var msg4 = { payload: msg2 }
msg.payload = msg4.payload;
return[msg.payload];

this incorrectly returns the payload as the message.

Try this instead

const startdatum = flow.get('startdate')
const einddatum =  flow.get('enddate')

msg.payload = {
    sum: "AUTO LADEN",
    des: "AUTO LADEN",
    sta: startdatum,
    end: einddatum
}

return msg
1 Like

First of all thank You for assisting.
I am strugeling with this for a week now.

I have done.what You asked :
this is the error :

This is the debug node info : {"sum":"AUTO LADEN","des":"AUTO LADEN","sta":"2025-03-01 12:12:00","end":"2025-03-01 13:12:00"}

this is the ised code :

[{"id":"ecfe3752ca47f229","type":"api-call-service","z":"7feba46b9875e560","name":"Create Calendar Event","server":"918a63e0.1bc5a","version":7,"debugenabled":false,"action":"calendar.create_event","floorId":[],"areaId":[],"deviceId":[],"entityId":["calendar.electricity"],"labelId":[],"data":"{\"summary\":\"AUTO LADEN\",\"description\":\"AUTO LADEN\",\"start_date_time\":\"2025-03-01 12:12:00\",\"end_date_time\":\"2025-03-01 13:12:00\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","blockInputOverrides":false,"domain":"calendar","service":"create_event","x":780,"y":4620,"wires":[[]]},{"id":"0516f056dabf6ece","type":"inject","z":"7feba46b9875e560","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":4620,"wires":[["ecfe3752ca47f229"]]},{"id":"97e76ca760ce6e66","type":"function","z":"7feba46b9875e560","name":"Create Event Data","func":"const startdatum = flow.get('startdate')\nconst einddatum = flow.get('enddate')\n\nmsg.payload = {\n    sum: \"AUTO LADEN\",\n    des: \"AUTO LADEN\",\n    sta: startdatum,\n    end: einddatum\n}\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":4480,"wires":[["5daeb51b0b6f3f60","aca92fef589d791c"]]},{"id":"20835c8456ab0ce2","type":"inject","z":"7feba46b9875e560","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":4480,"wires":[["97e76ca760ce6e66"]]},{"id":"5daeb51b0b6f3f60","type":"api-call-service","z":"7feba46b9875e560","name":"Create Calendar Event","server":"918a63e0.1bc5a","version":7,"debugenabled":false,"action":"calendar.create_event","floorId":[],"areaId":[],"deviceId":[],"entityId":["calendar.electricity"],"labelId":[],"data":"{{payload}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","blockInputOverrides":false,"domain":"calendar","service":"create_event","x":780,"y":4480,"wires":[[]]},{"id":"aca92fef589d791c","type":"debug","z":"7feba46b9875e560","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":4540,"wires":[]},{"id":"918a63e0.1bc5a","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

This is the Home assistant node I use

Since i dont use Home Assistant (most here do not) I have no idea what kind of options/payload the node accepts.

Can you show us where you have entered the value for the payload on the blue HA node?

you have JSON mode selected and what you have entered is NOT valid JSON (there are lots of online JSON validators you can use to test that)

What other options does this node have?

Change it to "J: expression" and enter payload

(no curly brackets, just payload by itself)

1 Like

THANKS SO MUCH...IT WORKS. Someone has a good link for me to study this stuff. I alway's got stuck with this JSON stuff. One more. Thanks to all who helped me.

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.


This post and this post should help to clarify the difference between Javascript objects and JSON.

I had also posted this question at https://community.home-assistant.io/ and posted the sollution there. I hope You don't mind i mentioned Your name for helping.

1 Like

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