Greetings!
I am new to home assistant with some very beginner/basic level knowledge about coding.
I am a pilot and hence my schedule is different each day. I have synched my schedule to a google calendar and have integrated the google calendar with home assistant.
the automation I want to achieve in node red is this:
when I leave the zone airport after my duty ends , notify my family that i have left the airport to come home … only when my duty has finished (basically comparing the current time to the attribute ‘duty_endtime’ in the payload (calendar.dharmil_schedule)
the problem I face is that i am not able to compare time (present time with duty end time) . the output of the flow i made is very random … it works sometime and outputs true only when i genuinely leave the airport post my flights but most times it send a false notification as soon as i leave the zone airport/take off irrespective of my duty time not finished
i am not sure if google calendar outputs the ‘duty_endtime’ as a string and i am trying to compare string with current timestamp. please do shed some light on this. i tried learning about comparing times in json but was not so successful
thank you so much you guys for helping this community has really helped and taught me a lot.
PS: sometime i also do 4 flights a day which involves shuttling between to cities like …example departing from 1)paris to rome 2) Rome to paris 3)Paris to milan 4)milan to paris
this is the node red flow i tried using.
[{“id”:“244b74487d24d384”,“type”:“tab”,“label”:“Flow 1”,“disabled”:false,“info”:""},{“id”:“dceb19fbad145dd9”,“type”:“comment”,“z”:“244b74487d24d384”,“name”:“Dharmil leaves home for flight”,“info”:"",“x”:200,“y”:80,“wires”:[]},{“id”:“0383d47d4496b975”,“type”:“ha-zone”,“z”:“244b74487d24d384”,“name”:“dharmil leaves”,“server”:“a1dbb521.14a988”,“version”:0,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entities”:[“person.dharmil”],“event”:“leave”,“zones”:[“zone.home”],“x”:111,“y”:219,“wires”:[[“8c285b155029a90e”]]},{“id”:“8c285b155029a90e”,“type”:“api-current-state”,“z”:“244b74487d24d384”,“name”:“roster “,“server”:“a1dbb521.14a988”,“version”:2,“outputs”:1,“halt_if”:””,“halt_if_type”:“str”,“halt_if_compare”:“is”,“entity_id”:“calendar.dharmil_schedule”,“state_type”:“str”,“blockInputOverrides”:false,“outputProperties”:[{“property”:“payload”,“propertyType”:“msg”,“value”:"",“valueType”:“entityState”},{“property”:“data”,“propertyType”:“msg”,“value”:"",“valueType”:“entity”}],“override_topic”:false,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“x”:90,“y”:280,“wires”:[[“e34538b4ccda1b61”]]},{“id”:“e34538b4ccda1b61”,“type”:“switch”,“z”:“244b74487d24d384”,“name”:“home base city check”,“property”:“data.attributes.message”,“propertyType”:“msg”,“rules”:[{“t”:“cont”,“v”:“currentcity”,“vt”:“str”}],“checkall”:“false”,“repair”:false,“outputs”:1,“x”:140,“y”:360,“wires”:[[“6d5ab2f433a80cca”]]},{“id”:“6d5ab2f433a80cca”,“type”:“api-current-state”,“z”:“244b74487d24d384”,“name”:“roster”,“server”:“a1dbb521.14a988”,“version”:2,“outputs”:1,“halt_if”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“entity_id”:“calendar.dharmil_schedule”,“state_type”:“str”,“blockInputOverrides”:false,“outputProperties”:[{“property”:“payload”,“propertyType”:“msg”,“value”:"",“valueType”:“entityState”},{“property”:“data”,“propertyType”:“msg”,“value”:"",“valueType”:“entity”}],“override_topic”:false,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“x”:250,“y”:280,“wires”:[[“fa9bbbf07dd347ee”]]},{“id”:“fa9bbbf07dd347ee”,“type”:“moment”,“z”:“244b74487d24d384”,“name”:“roster date”,“topic”:"",“input”:“data.attributes.start_time”,“inputType”:“msg”,“inTz”:“Asia/Calcutta”,“adjAmount”:0,“adjType”:“days”,“adjDir”:“add”,“format”:“MM/DD/YY”,“locale”:“C”,“output”:“payload”,“outputType”:“msg”,“outTz”:“Asia/Calcutta”,“x”:350,“y”:360,“wires”:[[“e3d2bda22357cddf”]]},{“id”:“e3d2bda22357cddf”,“type”:“switch”,“z”:“244b74487d24d384”,“name”:“date check”,“property”:“globaldate1”,“propertyType”:“global”,“rules”:[{“t”:“eq”,“v”:“payload”,“vt”:“msg”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:430,“y”:280,“wires”:[[“3ec4a6d099f12d83”,“7cbbd773200d1c11”]]},{“id”:“93dcac656d680c8a”,“type”:“delay”,“z”:“244b74487d24d384”,“name”:"",“pauseType”:“delay”,“timeout”:“45”,“timeoutUnits”:“minutes”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“allowrate”:false,“x”:750,“y”:360,“wires”:[[“0ec95988fcbdd06d”]]},{“id”:“3ec4a6d099f12d83”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“notify”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“family”,“entityId”:"",“data”:"{“message”:“Dharmil has left home for the airport”}",“dataType”:“jsonata”,“mergecontext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:430,“y”:220,“wires”:[[]]},{“id”:“e15de4107b3bbd8a”,“type”:“api-current-state”,“z”:“244b74487d24d384”,“name”:“city check”,“server”:“a1dbb521.14a988”,“version”:2,“outputs”:1,“halt_if”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“entity_id”:“sensor.cellphone_geocoded_location”,“state_type”:“str”,“blockInputOverrides”:false,“outputProperties”:[{“property”:“payload”,“propertyType”:“msg”,“value”:"",“valueType”:“entityState”},{“property”:“data”,“propertyType”:“msg”,“value”:"",“valueType”:“entity”}],“override_topic”:false,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“x”:1090,“y”:280,“wires”:[[“477f702c61c360b3”,“d1532fcbc313e375”,“5a264e940756c08d”]]},{“id”:“84ff0b57d90ef662”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“dharmil duty”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.dharmil_duty”,“data”:"",“dataType”:“jsonata”,“mergecontext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:1350,“y”:280,“wires”:[[]]},{“id”:“477f702c61c360b3”,“type”:“switch”,“z”:“244b74487d24d384”,“name”:“airport”,“property”:“data.attributes.Zones”,“propertyType”:“msg”,“rules”:[{“t”:“cont”,“v”:“airport”,“vt”:“str”},{“t”:“cont”,“v”:“airport 2”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1130,“y”:200,“wires”:[[“84ff0b57d90ef662”,“4eed3d38bbde56f4”],[]]},{“id”:“ab1573faee4a536e”,“type”:“inject”,“z”:“244b74487d24d384”,“name”:"",“props”:[{“p”:“payload”},{“p”:“topic”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“payload”:"",“payloadType”:“date”,“x”:480,“y”:140,“wires”:[[“0ec95988fcbdd06d”,“8c285b155029a90e”]]},{“id”:“d1532fcbc313e375”,“type”:“debug”,“z”:“244b74487d24d384”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:810,“y”:120,“wires”:[]},{“id”:“e7a9d42af06bb59e”,“type”:“comment”,“z”:“244b74487d24d384”,“name”:“Dharmil leaves airport after flight duty”,“info”:"",“x”:190,“y”:440,“wires”:[]},{“id”:“5a264e940756c08d”,“type”:“switch”,“z”:“244b74487d24d384”,“name”:“location check”,“property”:“data.attributes[“Areas Of Interest”]”,“propertyType”:“msg”,“rules”:[{“t”:“cont”,“v”:“airport”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:1160,“y”:360,“wires”:[[“f08779f65dfb30df”,“84ff0b57d90ef662”]]},{“id”:“f08779f65dfb30df”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“notify”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_cellphone”,“entityId”:"",“data”:"{“message”:“dharmil is at airport and duty turned on “}”,“dataType”:“jsonata”,“mergecontext”:”",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:1330,“y”:380,“wires”:[[]]},{“id”:“0ec95988fcbdd06d”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“Location update”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_cellphone”,“entityId”:"",“data”:"{“message”:“request_location_update”}",“dataType”:“jsonata”,“mergecontext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:880,“y”:280,“wires”:[[“e15de4107b3bbd8a”,“d1532fcbc313e375”]]},{“id”:“4eed3d38bbde56f4”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“notify”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_cellphone”,“entityId”:"",“data”:"{“message”:“dharmil is at aiport and duty turned on “}”,“dataType”:“jsonata”,“mergecontext”:”",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:1350,“y”:200,“wires”:[[]]},{“id”:“6f32f1d9fb8c7437”,“type”:“inject”,“z”:“244b74487d24d384”,“name”:"",“props”:[{“p”:“payload”},{“p”:“topic”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“payload”:"",“payloadType”:“date”,“x”:560,“y”:420,“wires”:[[“889aeea9af43fb51”]]},{“id”:“fdf46083fe271af8”,“type”:“delay”,“z”:“244b74487d24d384”,“name”:"",“pauseType”:“delay”,“timeout”:“30”,“timeoutUnits”:“minutes”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“allowrate”:false,“x”:750,“y”:200,“wires”:[[“0ec95988fcbdd06d”]]},{“id”:“7cbbd773200d1c11”,“type”:“time-range-switch”,“z”:“244b74487d24d384”,“name”:"",“lat”:“19.0999”,“lon”:“72.91737”,“startTime”:“22:30”,“endTime”:“08:30”,“startOffset”:0,“endOffset”:0,“x”:630,“y”:280,“wires”:[[“fdf46083fe271af8”],[“93dcac656d680c8a”]]},{“id”:“dc321b73cf4563ed”,“type”:“ha-zone”,“z”:“244b74487d24d384”,“name”:“left airport”,“server”:“a1dbb521.14a988”,“version”:0,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entities”:[“person.dharmil_rao”],“event”:“leave”,“zones”:[“zone.airport”],“x”:100,“y”:520,“wires”:[[“889aeea9af43fb51”]]},{“id”:“889aeea9af43fb51”,“type”:“api-current-state”,“z”:“244b74487d24d384”,“name”:“Dharmil duty”,“server”:“a1dbb521.14a988”,“version”:2,“outputs”:2,“halt_if”:“on”,“halt_if_type”:“str”,“halt_if_compare”:“is”,“entity_id”:“input_boolean.dharmil_duty”,“state_type”:“str”,“blockInputOverrides”:false,“outputProperties”:[{“property”:“payload”,“propertyType”:“msg”,“value”:"",“valueType”:“entityState”},{“property”:“data”,“propertyType”:“msg”,“value”:"",“valueType”:“entity”}],“override_topic”:false,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“x”:250,“y”:520,“wires”:[[“d500f2db8f8fca0e”,“45cd1920b9083f8c”],[]]},{“id”:“d500f2db8f8fca0e”,“type”:“api-current-state”,“z”:“244b74487d24d384”,“name”:“Duty end time”,“server”:“969aa5f8.2b8818”,“version”:2,“outputs”:1,“halt_if”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“entity_id”:“calendar.dharmil_schedule”,“state_type”:“str”,“blockInputOverrides”:false,“outputProperties”:[{“property”:“payload”,“propertyType”:“msg”,“value”:"",“valueType”:“entityState”},{“property”:“data”,“propertyType”:“msg”,“value”:"",“valueType”:“entity”}],“x”:420,“y”:560,“wires”:[[“02f3c7078d1be484”]]},{“id”:“45cd1920b9083f8c”,“type”:“function”,“z”:“244b74487d24d384”,“name”:"",“func”:“var sidoff=flow.get(‘flowtime’)\nmsg.payload = sidoff\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“libs”:[],“x”:420,“y”:500,“wires”:[[“3b06018f6e71e20c”]]},{“id”:“02f3c7078d1be484”,“type”:“moment”,“z”:“244b74487d24d384”,“name”:“duty endtime -45 mins”,“topic”:"",“input”:“data.attributes.end_time”,“inputType”:“msg”,“inTz”:“Asia/Calcutta”,“adjAmount”:“45”,“adjType”:“minutes”,“adjDir”:“subtract”,“format”:“DD/MM/YY, h:mm: A”,“locale”:“en”,“output”:“payload”,“outputType”:“msg”,“outTz”:“Asia/Calcutta”,“x”:640,“y”:560,“wires”:[[“3b06018f6e71e20c”,“5b92346a7863a5e6”]]},{“id”:“3b06018f6e71e20c”,“type”:“join”,“z”:“244b74487d24d384”,“name”:"",“mode”:“custom”,“build”:“array”,“property”:“payload”,“propertyType”:“msg”,“key”:“topic”,“joiner”:"\n",“joinerType”:“str”,“accumulate”:false,“timeout”:"",“count”:“2”,“reduceRight”:false,“reduceExp”:"",“reduceInit”:"",“reduceInitType”:"",“reduceFixup”:"",“x”:590,“y”:500,“wires”:[[“70029d602deec642”,“ad302db7a662d86f”]]},{“id”:“ad302db7a662d86f”,“type”:“debug”,“z”:“244b74487d24d384”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:750,“y”:420,“wires”:[]},{“id”:“5b92346a7863a5e6”,“type”:“debug”,“z”:“244b74487d24d384”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:810,“y”:560,“wires”:[]},{“id”:“70029d602deec642”,“type”:“function”,“z”:“244b74487d24d384”,“name”:“Compare Times”,“func”:“newmsg = {};\nif (msg.payload[0] <= msg.payload[1]) {\n newmsg.payload = “True”;\n} else {\n newmsg.payload = “False”;\n}\n\nreturn newmsg;”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“libs”:[],“x”:740,“y”:500,“wires”:[[“a04acb108e5eec6e”]]},{“id”:“a04acb108e5eec6e”,“type”:“switch”,“z”:“244b74487d24d384”,“name”:"",“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“True”,“vt”:“str”},{“t”:“eq”,“v”:“False”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:890,“y”:500,“wires”:[[“299afda15c512df5”],[“2fb1f2fe4634cf99”]]},{“id”:“299afda15c512df5”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“Notify Family”,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“family”,“entityId”:"",“data”:"{“message”:“Dharmil has left the airport to come home”}",“dataType”:“jsonata”,“mergecontext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:1050,“y”:460,“wires”:[[]]},{“id”:“2fb1f2fe4634cf99”,“type”:“api-call-service”,“z”:“244b74487d24d384”,“name”:“Notify Dharmil “,“server”:“a1dbb521.14a988”,“version”:3,“debugenabled”:false,“service_domain”:“notify”,“service”:“mobile_app_cellphone”,“entityId”:””,“data”:"{“message”:“you have left zone T2 but your duty time is not over”}",“dataType”:“jsonata”,“mergecontext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:1060,“y”:540,“wires”:[[]]},{“id”:“143cf7dabd6ef69a”,“type”:“moment”,“z”:“244b74487d24d384”,“name”:“current date & time”,“topic”:"",“input”:"",“inputType”:“msg”,“inTz”:“ETC/UTC”,“adjAmount”:0,“adjType”:“days”,“adjDir”:“add”,“format”:“DD/MM/YY, h:mm: A”,“locale”:“en”,“output”:"",“outputType”:“msg”,“outTz”:“Asia/Calcutta”,“x”:330,“y”:720,“wires”:[[“45342cee28b5f096”]]},{“id”:“933169c416526391”,“type”:“inject”,“z”:“244b74487d24d384”,“name”:"",“props”:[{“p”:“payload”},{“p”:“topic”,“vt”:“str”}],“repeat”:“58”,“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“payload”:"",“payloadType”:“date”,“x”:110,“y”:720,“wires”:[[“143cf7dabd6ef69a”,“c4d798d51fbb2f6e”,“26f9a6556e3036f6”]]},{“id”:“45342cee28b5f096”,“type”:“function”,“z”:“244b74487d24d384”,“name”:“flowtime”,“func”:“flow.set(“flowtime”,msg.payload);\nreturn msg;\n”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“libs”:[],“x”:500,“y”:720,“wires”:[[]]},{“id”:“c4d798d51fbb2f6e”,“type”:“moment”,“z”:“244b74487d24d384”,“name”:“current time”,“topic”:"",“input”:"",“inputType”:“msg”,“inTz”:“ETC/UTC”,“adjAmount”:0,“adjType”:“days”,“adjDir”:“add”,“format”:“h:mm A”,“locale”:“en”,“output”:"",“outputType”:“msg”,“outTz”:“Asia/Calcutta”,“x”:330,“y”:760,“wires”:[[“5d8e4ddf95f8dd9f”]]},{“id”:“5d8e4ddf95f8dd9f”,“type”:“function”,“z”:“244b74487d24d384”,“name”:“flowtimeoff”,“func”:“flow.set(“flowtimeoff”,msg.payload);\nreturn msg;\n”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“libs”:[],“x”:510,“y”:760,“wires”:[[]]},{“id”:“6d5726124bbfdf43”,“type”:“comment”,“z”:“244b74487d24d384”,“name”:“For duty end time”,“info”:"",“x”:700,“y”:760,“wires”:[]},{“id”:“2049374feb1dec9f”,“type”:“comment”,“z”:“244b74487d24d384”,“name”:“Date and Time for schedule”,“info”:"",“x”:720,“y”:720,“wires”:[]},{“id”:“26f9a6556e3036f6”,“type”:“function”,“z”:“244b74487d24d384”,“name”:“Global current date “,“func”:“var d = new Date();\nvar options = { timeZone: ‘Asia/calcutta’, year: ‘2-digit’, month: ‘2-digit’, day: ‘2-digit’};\nvar _resultDate = d.toLocaleDateString(‘en-US’, options);\nmsg.payload = _resultDate;\nglobal.set(“globaldate1”,msg.payload);\n//return msg;\n”,“outputs”:1,“noerr”:0,“initialize”:””,“finalize”:"",“libs”:[],“x”:330,“y”:660,“wires”:[[]]},{“id”:“a1dbb521.14a988”,“type”:“server”,“name”:“Home Assistant”,“version”:1,“addon”:true,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true,“cacheJson”:true},{“id”:“969aa5f8.2b8818”,“type”:“server”,“name”:“Home Assistant”,“version”:1,“legacy”:false,“addon”:true,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true,“cacheJson”:true}]