homeassistant-microsoft-todo
homeassistant-microsoft-todo copied to clipboard
Feature Request: Additional hidden JSON
Hi, i was looking into how this custom_component works and was checking how already established components work.
When looking at the official shopping_list component, we can see that all the different tasks (including the ID) is saved in a hidden .json file in the config directory. The same way the token is handled by this component.
It would be great if this component could do the same. In this way, it should also be possible to remove a task (since we know the ID) from both the HA list, and also the cloud. On top, may it be possible to use the same UI as currently possible for the shopping list where each item can individually be ticked (completed) and shown?
Currently looking into learning enough so I could help with the PRs... but from my latest progress it might still be a while until i can be of actual help...
Interesting idea. But I'm not quite sure if there is a way to integrate the shopping_list
this way :thinking: shopping_list
has it's own logic and I think synchronizing 2 different integrations probably won't be working. If you have an example of such integration please share.
I wonder if there is something similar for Todoist/Remember The Milk/etc, then it would be easier to implement the same for MS To Do. Currently, it should be possible to show MS To Do tasks using the calendar card but for managing tasks we probably need some custom card.
So a quick update from my side:
As i mentioned.. my python game is pretty weak.. however, i managed to do a nice 2way sync (basic) between the shopping list and todo application via NodeRed.
[{"id":"d12ae7ab.dbb1c8","type":"file in","z":"268cc0a0.83835","name":"","filename":"/config/.shopping_list.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":1510,"y":640,"wires":[["140d1852.0a19f8"]]},{"id":"140d1852.0a19f8","type":"json","z":"268cc0a0.83835","name":"","property":"payload","action":"","pretty":false,"x":1690,"y":640,"wires":[["c14da63b.be03d8"]]},{"id":"c14da63b.be03d8","type":"function","z":"268cc0a0.83835","name":"Check duplicate","func":"msg.payload = msg.payload.filter(element => element.name.includes(msg.name.name))\nreturn msg\n","outputs":1,"noerr":0,"x":1840,"y":640,"wires":[["db483068.88f9d"]]},{"id":"db483068.88f9d","type":"switch","z":"268cc0a0.83835","name":"","property":"payload","propertyType":"msg","rules":[{"t":"empty"}],"checkall":"true","repair":false,"outputs":1,"x":1990,"y":640,"wires":[["f1e941d.e9995c"]]},{"id":"6f2e15f2.4766bc","type":"comment","z":"268cc0a0.83835","name":"Function Node currently only checks if word is part of the name","info":"","x":1990,"y":600,"wires":[]},{"id":"38f4760b.fca93a","type":"function","z":"268cc0a0.83835","name":"Send Token","func":"newmsg = {}\nvar token = flow.get('token',\"storeInFile\");\n\nnewmsg.headers = {\n Authorization: \"Bearer \"+ token\n}\nreturn newmsg;","outputs":1,"noerr":0,"x":270,"y":640,"wires":[["36f50a25.39e446"]]},{"id":"a62afcf4.eeba2","type":"inject","z":"268cc0a0.83835","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":640,"wires":[["38f4760b.fca93a"]]},{"id":"82e78838.efb378","type":"json","z":"268cc0a0.83835","name":"","property":"payload","action":"","pretty":false,"x":570,"y":640,"wires":[["21221301.918ddc"]]},{"id":"36f50a25.39e446","type":"http request","z":"268cc0a0.83835","name":"Einkaufsliste","method":"GET","ret":"txt","paytoqs":false,"url":"https://graph.microsoft.com/beta/me/outlook/taskfolders('YOURTASKFOLDERID')/tasks","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":640,"wires":[["82e78838.efb378"]]},{"id":"978e1e47.a1fe9","type":"split","z":"268cc0a0.83835","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":880,"y":640,"wires":[["33eab883.0d75e8"]]},{"id":"21221301.918ddc","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"move","p":"payload.value","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"headers","pt":"msg"},{"t":"delete","p":"responseUrl","pt":"msg"},{"t":"delete","p":"statusCode","pt":"msg"},{"t":"delete","p":"redirectList","pt":"msg"},{"t":"delete","p":"parts","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":640,"wires":[["978e1e47.a1fe9"]]},{"id":"656e03a8.1f3d6c","type":"function","z":"268cc0a0.83835","name":"Get Item","func":"var name = msg.payload.subject\nvar complete = msg.payload.status\nvar id = msg.payload.id\n\nif (complete === 'notStarted'){\n complete = false;\n} else {\n complete = true;\n} \n\nvar msg1 = { payload:{complete,id,name}};\nreturn msg1\n","outputs":1,"noerr":0,"x":1140,"y":640,"wires":[["1e7c16b5.41cc39"]]},{"id":"1e7c16b5.41cc39","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"delete","p":"_msgid","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":640,"wires":[["d12ae7ab.dbb1c8"]]},{"id":"33eab883.0d75e8","type":"switch","z":"268cc0a0.83835","name":"Open","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"notStarted","vt":"str"},{"t":"eq","v":"completed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":640,"wires":[["656e03a8.1f3d6c"],[]]},{"id":"f1e941d.e9995c","type":"api-call-service","z":"268cc0a0.83835","name":"","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"shopping_list","service":"add_item","entityId":"","data":"{\"name\":\"{{name.name}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2180,"y":640,"wires":[[]]},{"id":"881874a8.4bfc78","type":"comment","z":"268cc0a0.83835","name":"Add Item to Shooping List if Name Does not already Exist","info":"","x":250,"y":600,"wires":[]},{"id":"e75f3164.106d9","type":"comment","z":"268cc0a0.83835","name":"Complete Item on Shooping List if it was completed recently in ToDo","info":"","x":280,"y":740,"wires":[]},{"id":"d0490b97.ea5b18","type":"function","z":"268cc0a0.83835","name":"Send Token","func":"newmsg = {}\nvar token = flow.get('token',\"storeInFile\");\n\nnewmsg.headers = {\n Authorization: \"Bearer \"+ token\n}\nreturn newmsg;","outputs":1,"noerr":0,"x":270,"y":780,"wires":[["a2d73e0a.c9a1c"]]},{"id":"c52fe18c.44808","type":"inject","z":"268cc0a0.83835","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":780,"wires":[["d0490b97.ea5b18"]]},{"id":"62ceb0ef.edd23","type":"json","z":"268cc0a0.83835","name":"","property":"payload","action":"","pretty":false,"x":570,"y":780,"wires":[["f3d7228a.4ecd8"]]},{"id":"a2d73e0a.c9a1c","type":"http request","z":"268cc0a0.83835","name":"Einkaufsliste","method":"GET","ret":"txt","paytoqs":false,"url":"https://graph.microsoft.com/beta/me/outlook/taskfolders('YOURTASKFOLDERID')/tasks","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":780,"wires":[["62ceb0ef.edd23"]]},{"id":"142115a9.5dd5ba","type":"split","z":"268cc0a0.83835","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":880,"y":780,"wires":[["26959d8f.d285c2"]]},{"id":"f3d7228a.4ecd8","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"move","p":"payload.value","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"headers","pt":"msg"},{"t":"delete","p":"responseUrl","pt":"msg"},{"t":"delete","p":"statusCode","pt":"msg"},{"t":"delete","p":"redirectList","pt":"msg"},{"t":"delete","p":"parts","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":780,"wires":[["142115a9.5dd5ba"]]},{"id":"9e8d70f3.57dab","type":"function","z":"268cc0a0.83835","name":"Get Item","func":"var name = msg.payload.subject\nvar complete = msg.payload.status\nvar id = msg.payload.id\nvar time = msg.payload.lastModifiedDateTime\n\nif (complete === 'notStarted'){\n complete = false;\n} else {\n complete = true;\n} \n\nvar msg1 = { payload:{complete,id,name,time}};\nreturn msg1\n","outputs":1,"noerr":0,"x":1140,"y":780,"wires":[["7f641024.fd859"]]},{"id":"7f641024.fd859","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"name","tot":"msg"},{"t":"delete","p":"_msgid","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":780,"wires":[["6a13126.857eaec"]]},{"id":"26959d8f.d285c2","type":"switch","z":"268cc0a0.83835","name":"Open","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"notStarted","vt":"str"},{"t":"eq","v":"completed","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":780,"wires":[[],["9e8d70f3.57dab"]]},{"id":"2add353d.4ac76a","type":"debug","z":"268cc0a0.83835","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2390,"y":780,"wires":[]},{"id":"6a13126.857eaec","type":"api-call-service","z":"268cc0a0.83835","name":"","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"shopping_list","service":"complete_item","entityId":"","data":"{\"name\":\"{{name.name}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2160,"y":780,"wires":[["2add353d.4ac76a"]]},{"id":"50dafb43.f40604","type":"server-events","z":"268cc0a0.83835","name":"","server":"2fba4297.e4145e","event_type":"shopping_list_updated","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":160,"y":920,"wires":[["32c25f48.c325e"]]},{"id":"52cebf32.ec711","type":"comment","z":"268cc0a0.83835","name":"Time Filter not yet introduced","info":"","x":1520,"y":740,"wires":[]},{"id":"47dfe485.dfabfc","type":"server-state-changed","z":"268cc0a0.83835","name":"Einkaufsliste","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"calendar.einkaufliste","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":110,"y":820,"wires":[["d0490b97.ea5b18"]]},{"id":"cbe5abdf.4053c8","type":"server-state-changed","z":"268cc0a0.83835","name":"Einkaufsliste","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"calendar.einkaufliste","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":110,"y":680,"wires":[["38f4760b.fca93a"]]},{"id":"fe5b828b.dc783","type":"comment","z":"268cc0a0.83835","name":"Add Item to ToDo if Name Does not already Exist","info":"","x":220,"y":880,"wires":[]},{"id":"32c25f48.c325e","type":"file in","z":"268cc0a0.83835","name":"ShoppingList JSON","filename":"/config/.shopping_list.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":410,"y":920,"wires":[["f73cdd3.3eb042"]]},{"id":"f73cdd3.3eb042","type":"json","z":"268cc0a0.83835","name":"","property":"payload","action":"","pretty":false,"x":570,"y":920,"wires":[["7bbc075.0cdcaf8"]]},{"id":"7bbc075.0cdcaf8","type":"split","z":"268cc0a0.83835","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":880,"y":920,"wires":[["f3bcf537.4e3388"]]},{"id":"f3bcf537.4e3388","type":"switch","z":"268cc0a0.83835","name":"Open","property":"payload.complete","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":920,"wires":[["fbd09450.a54678"],[]]},{"id":"385468e3.487c18","type":"api-current-state","z":"268cc0a0.83835","name":"Einkaufsliste","server":"2fba4297.e4145e","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"calendar.einkaufliste","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1470,"y":920,"wires":[["f4070065.8ef96"]]},{"id":"59a8e9fd.cc0808","type":"debug","z":"268cc0a0.83835","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2870,"y":920,"wires":[]},{"id":"f4070065.8ef96","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"data.attributes.all_tasks","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"last_changed","pt":"msg"},{"t":"delete","p":"last_updated","pt":"msg"},{"t":"delete","p":"context","pt":"msg"},{"t":"delete","p":"timeSinceChangedMs","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1640,"y":920,"wires":[["97db9b23.665688"]]},{"id":"fbd09450.a54678","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"delete","p":"_msgid","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":920,"wires":[["385468e3.487c18"]]},{"id":"78b16602.5f1048","type":"function","z":"268cc0a0.83835","name":"Check duplicate","func":"msg.payload = msg.payload.filter(element => element.name.includes(msg.name.name))\nreturn msg\n","outputs":1,"noerr":0,"x":2260,"y":920,"wires":[["158af26f.62ed6e"]]},{"id":"97db9b23.665688","type":"split","z":"268cc0a0.83835","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1800,"y":920,"wires":[["13561c61.c3c434"]]},{"id":"13561c61.c3c434","type":"change","z":"268cc0a0.83835","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.name","tot":"msg"},{"t":"delete","p":"_msgid","pt":"msg"},{"t":"delete","p":"data","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1960,"y":920,"wires":[["c5ef1a2b.e25b48"]]},{"id":"c5ef1a2b.e25b48","type":"join","z":"268cc0a0.83835","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":2110,"y":920,"wires":[["78b16602.5f1048"]]},{"id":"158af26f.62ed6e","type":"switch","z":"268cc0a0.83835","name":"","property":"payload","propertyType":"msg","rules":[{"t":"empty"}],"checkall":"true","repair":false,"outputs":1,"x":2410,"y":920,"wires":[["62a10403.d15c8c"]]},{"id":"62a10403.d15c8c","type":"api-call-service","z":"268cc0a0.83835","name":"","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"microsoft_todo","service":"ms_todo_new_task","entityId":"","data":"{\"subject\":\"{{name.name}}\",\"list_name\":\"Einkaufliste\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2640,"y":920,"wires":[["59a8e9fd.cc0808"]]},{"id":"2fba4297.e4145e","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
In order to do that, i am actually saving the Token from your ms_todo.json as flow.token so i can always call it.
What works: Tasks is created in ToDo (also works via Alexa) -> Create same task in the shopping list. Tasks completed in ToDo -> set as complete in shopping list. Task created in shopping list -> Create same task in ToDo
What doesnt work yet: Set complete / delete task in ToDo (The component does not support it yet, and if i try to send the command manual via HTTP Post request, I am getting an error message back from MS. I have not been able to understand yet what i need to do)
I have no idea if that helps you in anyway, but would be cool if this functionality could be done completely by your component. Are you planning to add completed/delete task?