Creating Add Calendar Events to Local Calendar in Node Red

Hi All,

I am hoping someone might be able to help me with a flow I want to implement.

Here is the scenario:

My garbage is normally collected every Tuesday, but if a holiday falls on a Monday, or Tuesday, garbage is collected on Wednesday.

I have the Holidays addon installed, with a Holiday helper called ‘Observed Holidays for Garage Collection’ that has specific holidays that garbage is not collected in it.

The state of the Holiday helper returns how many days until the next observed Holiday. (Example: ‘17’ *17 days until Memorial Day)

I also have a local calendar called “Garbage Collection”, that is empty.

What I would like to do is create a flow in Node Red that

  1. Runs every Wednesday at 12:00am
  2. Checks if the upcoming Monday or Tuesday is a Holiday, by checking if the Holiday Helper state has a value of 6 or 7 (6 days from Wednesday would mean that upcoming Monday is a observed holiday, and 7 days from Wednesday would mean that upcoming Tuesday is a observed holiday)
  3. If the value is not a 6 or 7, create a Calendar event for Garbage Collection for upcoming Tuesday (Normal Garbage Collection day)
  4. If the value is a 6 or 7, create a Calendar event for Garbage Collection for upcoming Wednesday (Holiday Garbage Collection day)

I have basically already created a ‘Injector’ node to trigger the automation on Wednesdays at 12am that calls one ‘Current State’ node that checks the Holiday Helper state to see if has a value of 6, and another to check if the value is 7.

What I am having an issue with is steps 3 and 4 from above. How do I create a add Calendar Event in my ‘Garbage Collection’ local calendar? And how do I determine what date a Tuesday or Wednesday may fall on?

Any help would be greatly appreciated.

[{"id":"e973fd14a812cdbe","type":"inject","z":"265e4c64d108bbce","name":"holiday on monday","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":266,"y":816,"wires":[["d7275ee916aabcb0"]]},{"id":"8654dfc7bbc182da","type":"inject","z":"265e4c64d108bbce","name":"holiday on tuesday","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":266,"y":864,"wires":[["989f75f06ea00a9d"]]},{"id":"8b75e931b5f4b277","type":"change","z":"265e4c64d108bbce","name":"fake current state (20days)","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":504,"y":768,"wires":[["709f22493da3a6dd"]]},{"id":"60ac61ccb795e1c0","type":"inject","z":"265e4c64d108bbce","name":"no holiday","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":236,"y":768,"wires":[["8b75e931b5f4b277"]]},{"id":"d7275ee916aabcb0","type":"change","z":"265e4c64d108bbce","name":"fake current state (6days)","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":494,"y":816,"wires":[["709f22493da3a6dd"]]},{"id":"989f75f06ea00a9d","type":"change","z":"265e4c64d108bbce","name":"fake current state (7days)","rules":[{"t":"set","p":"payload","pt":"msg","to":"7","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":494,"y":864,"wires":[["709f22493da3a6dd"]]},{"id":"709f22493da3a6dd","type":"switch","z":"265e4c64d108bbce","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"6","vt":"str"},{"t":"eq","v":"7","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":750,"y":768,"wires":[["7e4d58a33dd4764f"],["7e4d58a33dd4764f"],["b91bdc75361e2e52"]]},{"id":"1b9dd3d89061f046","type":"api-call-service","z":"265e4c64d108bbce","name":"","server":"","version":5,"debugenabled":false,"domain":"calendar","service":"create_event","areaId":[],"deviceId":[],"entityId":["calendar.test"],"data":"{\"summary\": \"Garbage day\", \"description\": payload = 7 ? \"(holiday)\": \"\",  \"in\": {\"days\": payload}}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1204,"y":768,"wires":[[]]},{"id":"7e4d58a33dd4764f","type":"change","z":"265e4c64d108bbce","name":"create Wednesday date","rules":[{"t":"set","p":"payload","pt":"msg","to":"7","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":942,"y":768,"wires":[["1b9dd3d89061f046"]]},{"id":"b91bdc75361e2e52","type":"change","z":"265e4c64d108bbce","name":"create Tuesday date","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":932,"y":816,"wires":[["1b9dd3d89061f046"]]}]

short version, replace input_number.test with your holiday sensor id

image

[{"id":"50407be95aec3e03","type":"api-call-service","z":"265e4c64d108bbce","name":"","server":"","version":5,"debugenabled":false,"domain":"calendar","service":"create_event","areaId":[],"deviceId":[],"entityId":["calendar.test"],"data":"(\t    $isHoliday := $number($entities(\"input_number.test\").state) in [6, 7] ? true : false;\t    \t    {\"summary\": \"Garbage day\", \"description\": $isHoliday ? \"On Wednesday because of holiday\",  \"in\": {\"days\": $isHoliday ? 7 : 6}}\t)","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":444,"y":928,"wires":[[]]},{"id":"ab4d9ee75fb8dc84","type":"inject","z":"265e4c64d108bbce","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":928,"wires":[["50407be95aec3e03"]]}]
1 Like