Opa pessoal, estou trazendo esse “sisteminha” que montei no home assistant + nodered. Existe inúmeros Apps que fazem isso, mas como gosto de centralizar tudo que posso no home assistant resolvi fazer essa parte de rastreio também.
Vou dar uma breve explicação de como funciona:
Campo rastreio como o próprio nome já diz, serve para inserir o número do rastreio pode ser maiúsculo ou minúsculo, mas precisa ser o número correto pois ele vai procurar no site https://www.linkcorreios.com.br/
abaixo você pode dar um nome para esse rastreio, exemplo: kit facas tramontina
Veja que mais abaixo tem um botão de salvar e outro de excluir, assim que colocar as informações de rastreio e o nome do objeto clique em salvar.
Vai jogar as informações abaixo:
Você pode adicionar quantos rastreios quiser, vai ser montado um rastreio em baixo do outro, ainda não verifiquei como fazer mas quero deixar ordenado por data ou algo assim.
Para excluir um rastreio você só precisa digitar o número e clicar no botão e o rastreio vai sumir da lista abaixo.
Coloquei também que toda vez identificar que o objeto foi entregue após 5min remove ele da lista de rastreio automaticamente.
CÓDIGO NODERED
[{"id":"c015c48fce75f9c9","type":"tab","label":"-Correios","disabled":false,"info":"","env":[]},{"id":"ae07ecc66c8046d6","type":"group","z":"c015c48fce75f9c9","name":"Incluir rastreio","style":{"label":true},"nodes":["3e28b7fdab4f7750","a153c3335ca05819","134f7cda13f54cd8","5fa1e1dbc614f4d3","e5d09652058e775f","a3e385d010427de2","0634969061f823eb","db4fb5b4f50d5866","d2260fb7215273fd","144da9a0c195cb2d","88db72fe4c06f808","62b0684cb2b7c0f9"],"x":54,"y":79,"w":1452,"h":202},{"id":"54e0143eed5c1066","type":"group","z":"c015c48fce75f9c9","name":"Excluir rastreio","style":{"label":true},"nodes":["32a4ba93fa09426f","383341586e1c320f","75e3834d810b8deb","d81b7a009ddc552c","d46d2f3ab62d353b","b1fb96abb4e97f63","fab313b91030c18e","b2c96cbc2bd406f1","a1ed40c0ccf1ea8a"],"x":54,"y":319,"w":932,"h":222},{"id":"09a0318c1ac459ab","type":"group","z":"c015c48fce75f9c9","name":"DEV","style":{"label":true},"nodes":["e56d3d2e35d36d8e","56a7527f53089e93","46ed6ebaa19fa473","b3c42ec242a69919","3005d3a6c0e95d17","e4cc69a8732cc199","07efbaed25b3a81c","f01b1a67f42b91d6","e7bc326d19b765b0","698e614262bdb4f7","46e75340e57a933a","d9aedb515fa9c822","8857dbc8664503b0"],"x":54,"y":779,"w":752,"h":262},{"id":"c7332bffc45dd380","type":"group","z":"c015c48fce75f9c9","name":"Atualizações dos rastreios ","style":{"label":true},"nodes":["08939fc99b8e31fb","d93e0a35b1b6cd53","c00b44544a19cefb","bbf6d10211ddd2ab","9578512b0e430c0b","8c5703699444b288","8696598ef04473b3","3ffa1e1da4ae7699","ef94e8d612e870cf","d02aebe0b6216089","50e6dd8468791fa5"],"x":64,"y":659,"w":1462,"h":82},{"id":"e212207a29628e36","type":"group","z":"c015c48fce75f9c9","name":"Mudança de status","style":{"label":true},"nodes":["2799f3eb8ba75757","b053d8e5be4c0ef1","0d5c30b276e3d024","101dd78e849ac0d1"],"x":74,"y":559,"w":562,"h":82},{"id":"3e28b7fdab4f7750","type":"function","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Headers","func":"msg.url = \"https://www.linkcorreios.com.br/?id=\" + msg.rastreio\nmsg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["a153c3335ca05819"]]},{"id":"a153c3335ca05819","type":"http request","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Site","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":650,"y":180,"wires":[["134f7cda13f54cd8"]]},{"id":"134f7cda13f54cd8","type":"html","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Status","property":"payload","outproperty":"status","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(1) > b","ret":"text","as":"single","x":770,"y":180,"wires":[["d2260fb7215273fd"]]},{"id":"5fa1e1dbc614f4d3","type":"api-current-state","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Rastreio","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_text.rastreio","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rastreio","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":140,"y":180,"wires":[["a3e385d010427de2","88db72fe4c06f808"]]},{"id":"e5d09652058e775f","type":"server-state-changed","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"SALVAR","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_button.salvar","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":140,"y":120,"wires":[["5fa1e1dbc614f4d3"]]},{"id":"a3e385d010427de2","type":"api-call-service","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Limpar texto","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_text","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_text.nome_objeto","input_text.rastreio"],"data":"{\"value\":\"\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":150,"y":240,"wires":[[]]},{"id":"32a4ba93fa09426f","type":"http request","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":750,"y":360,"wires":[[]]},{"id":"383341586e1c320f","type":"function","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"Headers","func":"msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \"+flow.get(\"token\"),\n}\n\nmsg.url = 'http://'+flow.get(\"ip\")+'/api/states/sensor.correios_' + msg.rastreio\n\n\nvar index = flow.get(\"rastreio\").indexOf(msg.rastreio);\nvar rastreio = flow.get(\"rastreio\");\nvar nome_objeto = flow.get(\"nome_objeto\");\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\", rastreio)\n nome_objeto.splice(index, 1);\n flow.set(\"nome_objeto\",nome_objeto)\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":360,"wires":[["32a4ba93fa09426f"]]},{"id":"0634969061f823eb","type":"function","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Criar sensor","func":"let arrayRastreio = flow.get(\"rastreio\") || [];\narrayRastreio.push(msg.rastreio);\nflow.set(\"rastreio\", arrayRastreio);\n\n\nlet arrayObjeto = flow.get(\"nome_objeto\") || [];\narrayObjeto.push(msg.nome_objeto);\nflow.set(\"nome_objeto\", arrayObjeto);\n\nmsg.entity_id = 'sensor.correios_' + msg.rastreio.toUpperCase()\n\nmsg.payload = {\n data: {\n state: msg.status,\n attributes: {\n rastreio: msg.rastreio,\n status: msg.status,\n data: msg.data,\n local: msg.local,\n destino: msg.destino,\n friendly_name: msg.nome_objeto.toUpperCase() + ' - ' + msg.rastreio.toUpperCase(),\n }\n }\n};\n\nreturn msg\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1290,"y":180,"wires":[["db4fb5b4f50d5866"]]},{"id":"db4fb5b4f50d5866","type":"ha-api","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"","server":"db1ab0af.caa65","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1430,"y":180,"wires":[[]]},{"id":"d2260fb7215273fd","type":"html","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Data","property":"payload","outproperty":"data","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(2)","ret":"text","as":"single","x":890,"y":180,"wires":[["144da9a0c195cb2d"]]},{"id":"144da9a0c195cb2d","type":"html","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Local","property":"payload","outproperty":"local","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(3)","ret":"text","as":"single","x":1010,"y":180,"wires":[["62b0684cb2b7c0f9"]]},{"id":"75e3834d810b8deb","type":"server-state-changed","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"EXCLUIR","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_button.excluir","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":360,"wires":[["d81b7a009ddc552c","d46d2f3ab62d353b"]]},{"id":"d81b7a009ddc552c","type":"api-current-state","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"Rastreio","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_text.rastreio","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rastreio","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":460,"y":360,"wires":[["383341586e1c320f"]]},{"id":"d46d2f3ab62d353b","type":"api-call-service","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"Limpar texto","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_text","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_text.nome_objeto","input_text.rastreio"],"data":"{\"value\":\"\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":150,"y":420,"wires":[[]]},{"id":"88db72fe4c06f808","type":"api-current-state","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Nome objeto","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_text.nome_objeto","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"nome_objeto","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":180,"wires":[["3e28b7fdab4f7750"]]},{"id":"62b0684cb2b7c0f9","type":"html","z":"c015c48fce75f9c9","g":"ae07ecc66c8046d6","name":"Destino","property":"payload","outproperty":"destino","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(4)","ret":"text","as":"single","x":1140,"y":180,"wires":[["0634969061f823eb"]]},{"id":"b1fb96abb4e97f63","type":"switch","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"= Objeto entregue ao destinatário","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"['Objeto entregue ao destinatário']","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":500,"wires":[["a1ed40c0ccf1ea8a"]]},{"id":"fab313b91030c18e","type":"function","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"Headers","func":"msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \" + flow.get(\"token\"),\n}\n\nmsg.url = 'http://' + flow.get(\"ip\") + '/api/states/sensor.correios_' + msg.data.new_state.attributes.rastreio\n\nvar index = flow.get(\"rastreio\").indexOf(msg.data.new_state.attributes.rastreio);\nvar rastreio = flow.get(\"rastreio\");\nvar nome_objeto = flow.get(\"nome_objeto\");\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\", rastreio)\n nome_objeto.splice(index, 1);\n flow.set(\"nome_objeto\", nome_objeto)\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":500,"wires":[["b2c96cbc2bd406f1"]]},{"id":"b2c96cbc2bd406f1","type":"http request","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":890,"y":500,"wires":[[]]},{"id":"e56d3d2e35d36d8e","type":"inject","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Revemor Rastreio","props":[{"p":"rastreio","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":820,"wires":[["56a7527f53089e93"]]},{"id":"08939fc99b8e31fb","type":"function","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Headers","func":"for (var i = 0; i < flow.get(\"rastreio\").length; i++) {\n msg.url = \"https://www.linkcorreios.com.br/?id=\" + flow.get(\"rastreio\")[i]\n msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n }\n\n msg.rastreio = flow.get(\"rastreio\")[i]\n msg.nome_objeto = flow.get(\"nome_objeto\")[i]\n\n flow.get(\"rastreio\")[i] + 1;\n\n node.send([msg]); \n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":220,"y":700,"wires":[["d93e0a35b1b6cd53"]]},{"id":"d93e0a35b1b6cd53","type":"http request","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Site","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":350,"y":700,"wires":[["d02aebe0b6216089"]]},{"id":"c00b44544a19cefb","type":"html","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Status","property":"payload","outproperty":"status","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(1) > b","ret":"text","as":"single","x":650,"y":700,"wires":[["bbf6d10211ddd2ab"]]},{"id":"bbf6d10211ddd2ab","type":"html","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Data","property":"payload","outproperty":"data","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(2)","ret":"text","as":"single","x":770,"y":700,"wires":[["9578512b0e430c0b"]]},{"id":"9578512b0e430c0b","type":"html","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Local","property":"payload","outproperty":"local","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(3)","ret":"text","as":"single","x":890,"y":700,"wires":[["8c5703699444b288"]]},{"id":"8c5703699444b288","type":"html","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Destino","property":"payload","outproperty":"destino","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(4)","ret":"text","as":"single","x":1020,"y":700,"wires":[["50e6dd8468791fa5"]]},{"id":"8696598ef04473b3","type":"ha-api","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"","server":"db1ab0af.caa65","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1450,"y":700,"wires":[[]]},{"id":"3005d3a6c0e95d17","type":"template","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Listar array","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{flow.rastreio}}\n{{flow.nome_objeto}}","output":"str","x":310,"y":880,"wires":[["e4cc69a8732cc199"]]},{"id":"e4cc69a8732cc199","type":"debug","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"listar array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":880,"wires":[]},{"id":"b3c42ec242a69919","type":"inject","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Listar","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":880,"wires":[["3005d3a6c0e95d17"]]},{"id":"56a7527f53089e93","type":"function","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Remover do array","func":"var index = flow.get(\"rastreio\").indexOf(msg.rastreio);\nvar rastreio = flow.get(\"rastreio\")\n\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\",rastreio)\n}\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":820,"wires":[["46ed6ebaa19fa473"]]},{"id":"46ed6ebaa19fa473","type":"debug","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"remover array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":580,"y":820,"wires":[]},{"id":"3ffa1e1da4ae7699","type":"inject","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Atualiza de 1 em 1 min ","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":125,"y":700,"wires":[["08939fc99b8e31fb"]],"l":false},{"id":"ef94e8d612e870cf","type":"function","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"Atualizar sensor","func":"msg.entity_id = 'sensor.correios_' + msg.rastreio.toUpperCase();\n\nmsg.payload = {\n data: {\n state: msg.status,\n attributes: {\n rastreio: msg.rastreio,\n status: msg.status,\n data: msg.data,\n local: msg.local,\n destino: msg.destino,\n friendly_name: msg.nome_objeto.toUpperCase() + ' - ' + msg.rastreio.toUpperCase(),\n }\n }\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":700,"wires":[["8696598ef04473b3"]]},{"id":"07efbaed25b3a81c","type":"inject","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Zerar Array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":940,"wires":[["f01b1a67f42b91d6"]]},{"id":"f01b1a67f42b91d6","type":"function","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Limpar array","func":"var clear = flow.get(\"rastreio\");\nclear = [] || [];\nflow.set(\"rastreio\",clear);\n\nvar clear2 = flow.get(\"nome_objeto\");\nclear2 = [] || [];\nflow.set(\"nome_objeto\", clear2);\n\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":940,"wires":[["e7bc326d19b765b0"]]},{"id":"e7bc326d19b765b0","type":"debug","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"array limpo","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":940,"wires":[]},{"id":"d02aebe0b6216089","type":"delay","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":500,"y":700,"wires":[["c00b44544a19cefb"]]},{"id":"698e614262bdb4f7","type":"function","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Headers","func":"msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \"+flow.get(\"token\"),\n}\n\nmsg.url = 'http://'+flow.get(\"ip\")+'/api/states/sensor.correios_' + msg.rastreio\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1000,"wires":[["46e75340e57a933a"]]},{"id":"46e75340e57a933a","type":"http request","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":510,"y":1000,"wires":[["d9aedb515fa9c822"]]},{"id":"d9aedb515fa9c822","type":"debug","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"remover sensor","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":1000,"wires":[]},{"id":"8857dbc8664503b0","type":"inject","z":"c015c48fce75f9c9","g":"09a0318c1ac459ab","name":"Deletar sensor","props":[{"p":"rastreio","v":"OQ230493415BR","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":1000,"wires":[["698e614262bdb4f7"]]},{"id":"072becd4635ae26d","type":"inject","z":"c015c48fce75f9c9","name":"Digitar Chave token e IP","props":[{"p":"payload"}],"repeat":"1800","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":75,"y":40,"wires":[["e9dc3a730bbd8033"]],"l":false},{"id":"e9dc3a730bbd8033","type":"change","z":"c015c48fce75f9c9","name":"Digitar Chave token e IP","rules":[{"t":"set","p":"token","pt":"flow","to":"eyJhbGciO","tot":"str"},{"t":"set","p":"ip","pt":"flow","to":"192.168.0.140:8123","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":40,"wires":[[]]},{"id":"a1ed40c0ccf1ea8a","type":"delay","z":"c015c48fce75f9c9","g":"54e0143eed5c1066","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":635,"y":500,"wires":[["fab313b91030c18e"]],"l":false},{"id":"1bee3575bda16d83","type":"server-state-changed","z":"c015c48fce75f9c9","name":"Excluir automaticamente","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"correios_","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":180,"y":500,"wires":[["b1fb96abb4e97f63"]]},{"id":"2799f3eb8ba75757","type":"server-state-changed","z":"c015c48fce75f9c9","g":"e212207a29628e36","name":"Aviso mudança de status","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"correios_","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":600,"wires":[["101dd78e849ac0d1"]]},{"id":"b053d8e5be4c0ef1","type":"template","z":"c015c48fce75f9c9","g":"e212207a29628e36","name":"MSG","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"📦 {{{data.new_state.attributes.friendly_name}}} \n__\n\n{{{data.new_state.attributes.status}}}\n\n{{{data.new_state.attributes.data}}}\n\n{{{data.new_state.attributes.destino}}}\n\n{{{data.new_state.attributes.local}}}\n\n\n","output":"str","x":510,"y":600,"wires":[["0d5c30b276e3d024"]]},{"id":"0d5c30b276e3d024","type":"link out","z":"c015c48fce75f9c9","g":"e212207a29628e36","name":"link out 19","mode":"link","links":["0d20d93e76ce11d7","f04403206e76f318"],"x":595,"y":600,"wires":[]},{"id":"50e6dd8468791fa5","type":"function","z":"c015c48fce75f9c9","g":"c7332bffc45dd380","name":"!= Null","func":"if (msg.data.length === 0) {\n msg.data[0] = null;\n return [msg, null];\n}\nelse {\n return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":700,"wires":[[],["ef94e8d612e870cf"]]},{"id":"101dd78e849ac0d1","type":"function","z":"c015c48fce75f9c9","g":"e212207a29628e36","name":"!= Null","func":"if (msg.data.new_state.attributes.data.length === 0) {\n msg.data.new_state.attributes.data[0] = null;\n return [msg, null];\n}\nelse {\n return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":600,"wires":[[],["b053d8e5be4c0ef1"]]},{"id":"db1ab0af.caa65","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}]
CÓDIGO DO CARD
type: vertical-stack
cards:
- type: entities
entities:
- entity: input_text.rastreio
- entity: input_text.nome_objeto
footer:
type: buttons
entities:
- input_button.salvar
- input_button.excluir
title: NÚMERO DE RASTREIO
- type: horizontal-stack
cards:
- type: markdown
content: >-
{% for sensor in states.sensor|selectattr('entity_id', 'search',
'correios')|sort(attribute='attributes.data', reverse=True) %}
{% if sensor.attributes.status == ['Objeto saiu para entrega ao
destinatário'] %}
<font color="red"><u><h3>{{ sensor.attributes.friendly_name
|join()}}</h3></u></font>
<font color="red">{{ sensor.attributes.status |join()}}</h3></font>
<font color="red">{{ sensor.attributes.data |join()}}</h3></font>
<font color="red">{{ sensor.attributes.destino |join()}}</h3></font>
<font color="red">{{ sensor.attributes.local |join()}}</h3></font>
{% else %}
<h3><u>{{ sensor.attributes.friendly_name |join()}}</u></h3>
{{ sensor.attributes.status |join()}}
{{ sensor.attributes.data |join()}}
{{ sensor.attributes.destino |join()}}
{{ sensor.attributes.local |join()}}
{% endif %}
{% endfor %}
title: STATUS RASTREIO
VAMOS PRECISAR DE 2 BOTÕES E 2 CAMPOS TEXTO
- Clique em configurações
- Dispositivos e serviços
- Entidade auxiliares
- Crie conforme o exemplo:
O id da entidade tem que ser exatamente como o da foto para funcionar
DETALHE MUITO IMPORTANTE, PARA QUE O NODERED CONSIGA EXCLUIR O RASTREIO DA LISTA, VOCÊ PRECISA CRIAR UM TOKEN NO HOME ASSISTANT
Para criar um token:
-
Clique no ícone do seu nome:
-
Desça e encontre a parte para criar token
- Dê um nome para o token e copie TODA a chave
- No node red clique no fluxo “Digitar Chave token e IP”
- Cole a chave no flow.token e o IP do seu homeassistant com a porta no flow.ip
- Só clicar no botão inject
Vocês vão precisar editar essa parte do fluxo caso queiram receber notificações telegram, whatsapp e para falar na alexa,
OBS: ainda esta em fase de testes, mas dentro do que eu preciso já está servindo e já quis compartilhar com vocês. Caso queiram alguma coisa diferente ou sugestão de melhorias me avisem que quando der um tempo tento implementar
#######################################################################
***** NOVA VERSÃO *****
- Adicionado a função de remover o objeto através de um input_select
#######################################################################
AÇÕES NECESSÁRIAS
- Importar novo código abaixo:
[{"id":"0dace93f1c62e709","type":"tab","label":"-Correios","disabled":false,"info":"","env":[]},{"id":"ea071e8da9d39124","type":"group","z":"0dace93f1c62e709","name":"Incluir rastreio","style":{"label":true},"nodes":["f215688aac7e67bb","404d5b69c1e40af2","a600ebca20c0968b","b5ee5028792ea8ba","237f67f2ca4ab536","79fba58b01c11c87","ff53093e2e9155d2","cc72f9f1b7fda6fd","6c040845867ff6a8","2733cd67e1978769","b1ed375c92445889","b8475e64f4b3cb63","22ce5d1975abff1a","2c6d126be43a048f","e12ea3e4b120efac","c288b536137d8b7f","9f2530ef2c9c5426","25d0d5e83406a5ed","fd08bd6356577e16"],"x":34,"y":199,"w":1572,"h":202},{"id":"adb353b90d4bbedb","type":"group","z":"0dace93f1c62e709","name":"Excluir rastreio","style":{"label":true},"nodes":["04f55063a767d56e","d77b94517384bea3","c8249e43b7705297","bdabd4c81e1309ef","b1a2204e1e301956","5ae184bfa0ef8c3e","6cdec18df7cd0e52","4e7c42d01a3f26d6","d26cd1f99381882b","df9ec96ad35274ab","4315c71adaa2ad30","e94f5ee3c580f66f","ca3f516e4f0ee95d","5f37254d17edc2b4","c1efd4a606eb9588","2cbf0fc39024983d","7d30202b0766f77c"],"x":34,"y":419,"w":1252,"h":222},{"id":"86677324bf9ac5d5","type":"group","z":"0dace93f1c62e709","name":"DEV","style":{"label":true},"nodes":["8d3062d99d027706","d7c5785ecede29b7","6548be5899f59b91","0a7db1c063cfa5d7","c174c3b3101d4262","a947da941e97c655","7c62383f8de137ae","6094c75c2b4ea31c","46f3c22ae5e38e3a","b9737211cc4333fb","7883a2e578eb7ada","6b51a82b7083077f","12b9b0629c827122"],"x":34,"y":959,"w":752,"h":262},{"id":"91ea8b8ecc076fd8","type":"group","z":"0dace93f1c62e709","name":"Atualizações dos rastreios ","style":{"label":true},"nodes":["1600e2e5189d4151","9024c307453b89df","996091b7f3bec5b6","a614af9e407b0f79","62310de63bee4094","b517f75bbda0a73b","02a520b2ac3ae3c6","0afd745cb7d74494","75f4be3092a5efd8","ae75eeea82e9e31e","030dbae2bd6af67b"],"x":24,"y":859,"w":1462,"h":82},{"id":"e1c505609255ef96","type":"group","z":"0dace93f1c62e709","name":"Mudança de status","style":{"label":true},"nodes":["987d968b888972f4","4acf0b6e86c06cff","ece02265c4aba933","40467c538ceb786a","8bf30de06077ee63","93e3da0b98a668d1","a58efac89ff2450d","4215b6ab806a9d83","8382b3978128ee31","fa556b1a46bca79e","deabae80d553e27d"],"x":34,"y":679,"w":1342,"h":162},{"id":"2fee2da68df7bc00","type":"inject","z":"0dace93f1c62e709","name":"Digitar Chave token e IP","props":[{"p":"payload"}],"repeat":"1800","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":75,"y":40,"wires":[["965a10599f527867"]],"l":false},{"id":"965a10599f527867","type":"change","z":"0dace93f1c62e709","name":"Digitar Chave token e IP","rules":[{"t":"set","p":"token","pt":"flow","to":"","tot":"str"},{"t":"set","p":"ip","pt":"flow","to":"192.168.0.140:8123","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":40,"wires":[[]]},{"id":"f215688aac7e67bb","type":"function","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Headers","func":"msg.url = \"https://www.linkcorreios.com.br/?id=\" + msg.rastreio\nmsg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":300,"wires":[["404d5b69c1e40af2"]]},{"id":"404d5b69c1e40af2","type":"http request","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Site","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":750,"y":300,"wires":[["a600ebca20c0968b"]]},{"id":"a600ebca20c0968b","type":"html","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Status","property":"payload","outproperty":"status","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(1) > b","ret":"text","as":"single","x":870,"y":300,"wires":[["6c040845867ff6a8"]]},{"id":"b5ee5028792ea8ba","type":"api-current-state","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Rastreio","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_text.correios_rastreio","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rastreio","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":120,"y":300,"wires":[["79fba58b01c11c87","22ce5d1975abff1a"]]},{"id":"237f67f2ca4ab536","type":"server-state-changed","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"SALVAR","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_button.correios_salvar","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":120,"y":240,"wires":[["b5ee5028792ea8ba","e12ea3e4b120efac"]]},{"id":"79fba58b01c11c87","type":"api-call-service","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Limpar texto","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_text","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_text.correios_nome_objeto","input_text.correios_rastreio"],"data":"{\"value\":\"\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":130,"y":360,"wires":[["2c6d126be43a048f"]]},{"id":"ff53093e2e9155d2","type":"function","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Criar sensor","func":"let arrayRastreio = flow.get(\"rastreio\") || [];\narrayRastreio.push(msg.rastreio);\nflow.set(\"rastreio\", arrayRastreio);\n\n\nlet arrayObjeto = flow.get(\"nome_objeto\") || [];\narrayObjeto.push(msg.nome_objeto);\nflow.set(\"nome_objeto\", arrayObjeto);\n\nlet arrayNotificacao = flow.get(\"notificacao\") || [];\narrayNotificacao.push(msg.notificacao);\nflow.set(\"notificacao\", arrayNotificacao);\n\nmsg.entity_id = 'sensor.correios_' + msg.rastreio.toUpperCase()\n\nmsg.payload = {\n data: {\n state: msg.status,\n attributes: {\n rastreio: msg.rastreio,\n status: msg.status,\n notificacao: msg.notificacao,\n data: msg.data,\n local: msg.local,\n destino: msg.destino,\n friendly_name: msg.nome_objeto.toUpperCase() + ' - ' + msg.rastreio.toUpperCase(),\n }\n }\n};\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1390,"y":300,"wires":[["cc72f9f1b7fda6fd"]]},{"id":"cc72f9f1b7fda6fd","type":"ha-api","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"","server":"db1ab0af.caa65","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1530,"y":300,"wires":[[]]},{"id":"6c040845867ff6a8","type":"html","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Data","property":"payload","outproperty":"data","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(2)","ret":"text","as":"single","x":990,"y":300,"wires":[["2733cd67e1978769"]]},{"id":"2733cd67e1978769","type":"html","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Local","property":"payload","outproperty":"local","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(3)","ret":"text","as":"single","x":1110,"y":300,"wires":[["b8475e64f4b3cb63"]]},{"id":"b1ed375c92445889","type":"api-current-state","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Nome objeto","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_text.correios_nome_objeto","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"nome_objeto","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":300,"wires":[["f215688aac7e67bb"]]},{"id":"b8475e64f4b3cb63","type":"html","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Destino","property":"payload","outproperty":"destino","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(4)","ret":"text","as":"single","x":1240,"y":300,"wires":[["ff53093e2e9155d2"]]},{"id":"22ce5d1975abff1a","type":"api-current-state","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Notificação","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.correios_notificacao","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"notificacao","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":300,"wires":[["b1ed375c92445889"]]},{"id":"2c6d126be43a048f","type":"api-call-service","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Limpar select","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_select","service":"select_option","areaId":[],"deviceId":[],"entityId":["input_select.correios_notificacao"],"data":"{\"option\":\"Sim\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":370,"y":360,"wires":[[]]},{"id":"e12ea3e4b120efac","type":"delay","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":235,"y":240,"wires":[["c288b536137d8b7f"]],"l":false},{"id":"c288b536137d8b7f","type":"ha-get-entities","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Pegar sensores","server":"db1ab0af.caa65","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.correios_","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"sensores","output_results_count":1,"x":480,"y":240,"wires":[["9f2530ef2c9c5426"]]},{"id":"9f2530ef2c9c5426","type":"function","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"function","func":"// Inicializar o array de opções\nvar options = [];\n\n// Loop através do array msg.sensores\nfor (var i = 0; i < msg.sensores.length; i++) {\n // Adicionar o valor atual de msg.sensores[i].entity_id ao array de opções\n options.push(msg.sensores[i].attributes.friendly_name);\n}\n\n// Definir as opções no objeto msg.payload.data\nmsg.payload = {\n data: {\n \"options\": options\n }\n}\n\n// Enviar a mensagem modificada para o próximo nó\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":240,"wires":[["25d0d5e83406a5ed"]]},{"id":"25d0d5e83406a5ed","type":"api-call-service","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"Criar lista","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_select","service":"set_options","areaId":[],"deviceId":[],"entityId":["input_select.rastreio"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":240,"wires":[[]]},{"id":"fd08bd6356577e16","type":"link in","z":"0dace93f1c62e709","g":"ea071e8da9d39124","name":"link in 55","links":["e94f5ee3c580f66f","4315c71adaa2ad30"],"x":325,"y":240,"wires":[["c288b536137d8b7f"]]},{"id":"04f55063a767d56e","type":"http request","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":570,"y":460,"wires":[["e94f5ee3c580f66f","7d30202b0766f77c"]]},{"id":"d77b94517384bea3","type":"function","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Headers","func":"let partes = msg.rastreio.split('-');\nlet resultado = partes.pop().trim().toUpperCase();\nmsg.rastreio = resultado;\n\nmsg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \"+flow.get(\"token\"),\n}\n\nmsg.url = 'http://'+flow.get(\"ip\")+'/api/states/sensor.correios_' + msg.rastreio\n\n\nvar index = flow.get(\"rastreio\").indexOf(msg.rastreio);\nvar rastreio = flow.get(\"rastreio\");\nvar nome_objeto = flow.get(\"nome_objeto\");\nvar notificacao = flow.get(\"notificacao\")\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\", rastreio)\n nome_objeto.splice(index, 1);\n flow.set(\"nome_objeto\",nome_objeto)\n notificacao.splice(index, 1);\n flow.set(\"notificacao\", notificacao)\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":460,"wires":[["04f55063a767d56e"]]},{"id":"c8249e43b7705297","type":"server-state-changed","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"EXCLUIR","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_button.correios_excluir","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":460,"wires":[["b1a2204e1e301956","bdabd4c81e1309ef"]]},{"id":"bdabd4c81e1309ef","type":"api-current-state","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Rastreio","server":"db1ab0af.caa65","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.rastreio","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"rastreio","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":280,"y":460,"wires":[["d77b94517384bea3"]]},{"id":"b1a2204e1e301956","type":"api-call-service","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Limpar texto","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_text","service":"set_value","areaId":[],"deviceId":[],"entityId":["input_text.correios_nome_objeto","input_text.correios_rastreio"],"data":"{\"value\":\"\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":130,"y":520,"wires":[[]]},{"id":"5ae184bfa0ef8c3e","type":"switch","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"= Objeto entregue ao destinatário","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"['Objeto entregue ao destinatário']","vt":"str"},{"t":"eq","v":"['Objeto entregue ao remetente']","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":440,"y":600,"wires":[["d26cd1f99381882b"],["d26cd1f99381882b"]]},{"id":"6cdec18df7cd0e52","type":"function","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Headers","func":"msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \" + flow.get(\"token\"),\n}\n\nmsg.url = 'http://' + flow.get(\"ip\") + '/api/states/sensor.correios_' + msg.data.new_state.attributes.rastreio\n\nvar index = flow.get(\"rastreio\").indexOf(msg.data.new_state.attributes.rastreio);\nvar rastreio = flow.get(\"rastreio\");\nvar nome_objeto = flow.get(\"nome_objeto\");\nvar notificacao = flow.get(\"notificacao\");\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\", rastreio)\n nome_objeto.splice(index, 1);\n flow.set(\"nome_objeto\", nome_objeto)\n notificacao.splice(index, 1);\n flow.set(\"notificacao\", notificacao)\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":600,"wires":[["4e7c42d01a3f26d6"]]},{"id":"4e7c42d01a3f26d6","type":"http request","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":870,"y":600,"wires":[["4315c71adaa2ad30"]]},{"id":"d26cd1f99381882b","type":"delay","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":625,"y":600,"wires":[["6cdec18df7cd0e52"]],"l":false},{"id":"df9ec96ad35274ab","type":"server-state-changed","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Excluir automaticamente","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.correios_","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":600,"wires":[["5ae184bfa0ef8c3e"]]},{"id":"4315c71adaa2ad30","type":"link out","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"link out 74","mode":"link","links":["392e29fa7c841991","4889d89cd6c1f2c0","fd08bd6356577e16","6a50ed49d7a7d474"],"x":975,"y":600,"wires":[]},{"id":"e94f5ee3c580f66f","type":"link out","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"link out 73","mode":"link","links":["392e29fa7c841991","fd08bd6356577e16","6a50ed49d7a7d474"],"x":665,"y":460,"wires":[]},{"id":"ca3f516e4f0ee95d","type":"ha-get-entities","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Pegar sensores","server":"db1ab0af.caa65","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"sensor.correios_","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"sensores","output_results_count":1,"x":820,"y":460,"wires":[["2cbf0fc39024983d"]]},{"id":"5f37254d17edc2b4","type":"function","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"function","func":"// Inicializar o array de opções\nvar options = [];\n\nif (msg.sensores[0] != ''){\n // Loop através do array msg.sensores\n for (var i = 0; i < msg.sensores.length; i++) {\n // Adicionar o valor atual de msg.sensores[i].entity_id ao array de opções\n options.push(msg.sensores[i].attributes.friendly_name);\n }\n}\nelse {\n options = msg.sensores[0];\n}\n\n// Definir as opções no objeto msg.payload.data\nmsg.payload = {\n data: {\n \"options\": options\n }\n}\n\n// Enviar a mensagem modificada para o próximo nó\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":460,"wires":[["c1efd4a606eb9588"]]},{"id":"c1efd4a606eb9588","type":"api-call-service","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"Criar lista","server":"db1ab0af.caa65","version":5,"debugenabled":false,"domain":"input_select","service":"set_options","areaId":[],"deviceId":[],"entityId":["input_select.rastreio"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1200,"y":460,"wires":[[]]},{"id":"2cbf0fc39024983d","type":"function","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"function 33","func":"if (msg.sensores.length === 0) {\n msg.sensores[0] = \"\";\n return [msg, null];\n}\nelse {\n return [null, msg];\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":935,"y":460,"wires":[["5f37254d17edc2b4"]],"l":false},{"id":"7d30202b0766f77c","type":"delay","z":"0dace93f1c62e709","g":"adb353b90d4bbedb","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":705,"y":460,"wires":[["ca3f516e4f0ee95d"]],"l":false},{"id":"8d3062d99d027706","type":"inject","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Revemor Rastreio","props":[{"p":"rastreio","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":1000,"wires":[["d7c5785ecede29b7"]]},{"id":"d7c5785ecede29b7","type":"function","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Remover do array","func":"var index = flow.get(\"rastreio\").indexOf(msg.rastreio);\nvar rastreio = flow.get(\"rastreio\")\n\n\nif (index !== -1) {\n rastreio.splice(index, 1);\n flow.set(\"rastreio\",rastreio)\n}\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":1000,"wires":[["6548be5899f59b91"]]},{"id":"6548be5899f59b91","type":"debug","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"remover array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":560,"y":1000,"wires":[]},{"id":"0a7db1c063cfa5d7","type":"inject","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Listar","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":1060,"wires":[["c174c3b3101d4262"]]},{"id":"c174c3b3101d4262","type":"template","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Listar array","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{flow.rastreio}}\n{{flow.nome_objeto}}\n{{flow.notificacao}}","output":"str","x":290,"y":1060,"wires":[["a947da941e97c655"]]},{"id":"a947da941e97c655","type":"debug","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"listar array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":1060,"wires":[]},{"id":"7c62383f8de137ae","type":"inject","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Zerar Array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":1120,"wires":[["6094c75c2b4ea31c"]]},{"id":"6094c75c2b4ea31c","type":"function","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Limpar array","func":"var clear_rastreio = flow.get(\"rastreio\");\nclear_rastreio = [] || [];\nflow.set(\"rastreio\", clear_rastreio);\n\nvar clear_nome_objeto = flow.get(\"nome_objeto\");\nclear_nome_objeto = [] || [];\nflow.set(\"nome_objeto\", clear_nome_objeto);\n\nvar clear_notificacao = flow.get(\"notificacao\");\nclear_notificacao = [] || [];\nflow.set(\"notificacao\", clear_notificacao);\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":1120,"wires":[["46f3c22ae5e38e3a"]]},{"id":"46f3c22ae5e38e3a","type":"debug","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"array limpo","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":1120,"wires":[]},{"id":"b9737211cc4333fb","type":"function","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Headers","func":"msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n \"Authorization\": \"Bearer \"+flow.get(\"token\"),\n}\n\nmsg.url = 'http://'+flow.get(\"ip\")+'/api/states/sensor.correios_' + msg.rastreio\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":1180,"wires":[["7883a2e578eb7ada"]]},{"id":"7883a2e578eb7ada","type":"http request","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"","method":"DELETE","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":490,"y":1180,"wires":[["6b51a82b7083077f"]]},{"id":"6b51a82b7083077f","type":"debug","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"remover sensor","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":1180,"wires":[]},{"id":"12b9b0629c827122","type":"inject","z":"0dace93f1c62e709","g":"86677324bf9ac5d5","name":"Deletar sensor","props":[{"p":"rastreio","v":"NL658154191BR","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":1180,"wires":[["b9737211cc4333fb"]]},{"id":"1600e2e5189d4151","type":"function","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Headers","func":"for (var i = 0; i < flow.get(\"rastreio\").length; i++) {\n msg.url = \"https://www.linkcorreios.com.br/?id=\" + flow.get(\"rastreio\")[i]\n msg.headers = {\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/50.0.2661.102 Safari/537.36\",\n }\n\n msg.rastreio = flow.get(\"rastreio\")[i]\n msg.nome_objeto = flow.get(\"nome_objeto\")[i]\n msg.notificacao = flow.get(\"notificacao\")[i]\n\n flow.get(\"rastreio\")[i] + 1;\n\n node.send([msg]); \n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":900,"wires":[["9024c307453b89df"]]},{"id":"9024c307453b89df","type":"http request","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Site","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":310,"y":900,"wires":[["ae75eeea82e9e31e"]]},{"id":"996091b7f3bec5b6","type":"html","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Status","property":"payload","outproperty":"status","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(1) > b","ret":"text","as":"single","x":610,"y":900,"wires":[["a614af9e407b0f79"]]},{"id":"a614af9e407b0f79","type":"html","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Data","property":"payload","outproperty":"data","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(2)","ret":"text","as":"single","x":730,"y":900,"wires":[["62310de63bee4094"]]},{"id":"62310de63bee4094","type":"html","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Local","property":"payload","outproperty":"local","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(3)","ret":"text","as":"single","x":850,"y":900,"wires":[["b517f75bbda0a73b"]]},{"id":"b517f75bbda0a73b","type":"html","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Destino","property":"payload","outproperty":"destino","tag":"#page > main > div.container.margin_30_5 > div > div > div.singlepost > ul:nth-child(3) > li:nth-child(4)","ret":"text","as":"single","x":980,"y":900,"wires":[["030dbae2bd6af67b"]]},{"id":"02a520b2ac3ae3c6","type":"ha-api","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"","server":"db1ab0af.caa65","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1410,"y":900,"wires":[[]]},{"id":"0afd745cb7d74494","type":"inject","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Atualiza de 1 em 1 min ","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":85,"y":900,"wires":[["1600e2e5189d4151"]],"l":false},{"id":"75f4be3092a5efd8","type":"function","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"Atualizar sensor","func":"msg.entity_id = 'sensor.correios_' + msg.rastreio.toUpperCase();\n\nmsg.payload = {\n data: {\n state: msg.status,\n attributes: {\n rastreio: msg.rastreio,\n status: msg.status,\n data: msg.data,\n notificacao: msg.notificacao,\n local: msg.local,\n destino: msg.destino,\n friendly_name: msg.nome_objeto.toUpperCase() + ' - ' + msg.rastreio.toUpperCase(),\n }\n }\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1260,"y":900,"wires":[["02a520b2ac3ae3c6"]]},{"id":"ae75eeea82e9e31e","type":"delay","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"","pauseType":"rate","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":460,"y":900,"wires":[["996091b7f3bec5b6"]]},{"id":"030dbae2bd6af67b","type":"function","z":"0dace93f1c62e709","g":"91ea8b8ecc076fd8","name":"!= Null","func":"if (msg.data.length === 0) {\n msg.data[0] = null;\n return [msg, null];\n}\nelse {\n return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1110,"y":900,"wires":[[],["75f4be3092a5efd8"]]},{"id":"987d968b888972f4","type":"server-state-changed","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"Aviso mudança de status","server":"db1ab0af.caa65","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.correios_","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":760,"wires":[["a58efac89ff2450d"]]},{"id":"4acf0b6e86c06cff","type":"switch","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"Notificacao = Sim / Saiu para entrega","property":"data.new_state.attributes.notificacao","propertyType":"msg","rules":[{"t":"eq","v":"Sim","vt":"str"},{"t":"eq","v":"Saiu para entrega","vt":"str"},{"t":"eq","v":"Objeto entregue","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":570,"y":760,"wires":[["40467c538ceb786a"],["8bf30de06077ee63"],["4215b6ab806a9d83"]]},{"id":"ece02265c4aba933","type":"link out","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"link out 19","mode":"link","links":["0d20d93e76ce11d7","f04403206e76f318"],"x":975,"y":720,"wires":[]},{"id":"40467c538ceb786a","type":"template","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"Todas notificações","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"📦 {{{data.new_state.attributes.friendly_name}}} \n__\n\n{{{data.new_state.attributes.status}}}\n\n{{{data.new_state.attributes.data}}}\n\n{{{data.new_state.attributes.destino}}}\n\n{{{data.new_state.attributes.local}}}\n\n\n","output":"str","x":850,"y":720,"wires":[["ece02265c4aba933"]]},{"id":"8bf30de06077ee63","type":"switch","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"= Objeto saiu para entrega ao destinatário","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"['Objeto saiu para entrega ao destinatário']","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":920,"y":760,"wires":[["93e3da0b98a668d1"]]},{"id":"93e3da0b98a668d1","type":"template","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"Saiu para entrega","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"📦 {{{data.new_state.attributes.friendly_name}}} \n__\n\n{{{data.new_state.attributes.status}}}\n\n{{{data.new_state.attributes.data}}}\n\n{{{data.new_state.attributes.destino}}}\n\n{{{data.new_state.attributes.local}}}\n\n\n","output":"str","x":1210,"y":760,"wires":[["fa556b1a46bca79e"]]},{"id":"a58efac89ff2450d","type":"function","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"!= Null","func":"if (msg.data.new_state.attributes.data.length === 0) {\n msg.data.new_state.attributes.data[0] = null;\n return [msg, null];\n}\nelse {\n return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":760,"wires":[[],["4acf0b6e86c06cff"]]},{"id":"4215b6ab806a9d83","type":"switch","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"= Objeto entregue ao destinatário","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"['Objeto entregue ao destinatário']","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":900,"y":800,"wires":[["8382b3978128ee31"]]},{"id":"8382b3978128ee31","type":"template","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"Objeto entregue","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"📦 {{{data.new_state.attributes.friendly_name}}} \n__\n\n{{{data.new_state.attributes.status}}}\n\n{{{data.new_state.attributes.data}}}\n\n{{{data.new_state.attributes.destino}}}\n\n{{{data.new_state.attributes.local}}}\n\n\n","output":"str","x":1200,"y":800,"wires":[["deabae80d553e27d"]]},{"id":"fa556b1a46bca79e","type":"link out","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"link out 76","mode":"link","links":["0d20d93e76ce11d7","f04403206e76f318"],"x":1335,"y":760,"wires":[]},{"id":"deabae80d553e27d","type":"link out","z":"0dace93f1c62e709","g":"e1c505609255ef96","name":"link out 77","mode":"link","links":["0d20d93e76ce11d7","f04403206e76f318"],"x":1335,"y":800,"wires":[]},{"id":"db1ab0af.caa65","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}]
OBS: o código acima já esta com o nó do token, então se forem atualizar o código façam um backup do token de vocês para não precisar gerar um novo.
-
Ir em Configurações > Dispositivos > Entidades Ajudantes e criar um select com o nome de rastreio, a entidade tem que ficar
input_select.correios
-
Importar o novo código do cartão:
type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: custom:mushroom-template-card
primary: Novo
badge_icon: mdi:plus
secondary: Rastreamento
icon: mdi:package-variant-closed-plus
fill_container: true
layout: horizontal
icon_color: green
tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.popup
data:
title: Adicionar Rastreio
right_button: Salvar
right_button_action:
service: input_button.press
data:
entity_id: input_button.correios_salvar
content:
type: entities
entities:
- entity: input_select.correios_notificacao
name: Deseja receber notificações?
icon: mdi:bell-ring
- entity: input_text.correios_rastreio
name: Qual o Código de Rastreamento?
icon: mdi:package-variant-closed
- entity: input_text.correios_nome_objeto
name: Qual nome do Objeto?
icon: mdi:form-textbox
card_mod:
style: |
ha-card {
--ha-card-background: white;
}
- type: custom:mushroom-template-card
primary: Excluir
secondary: Rastreamento
icon: mdi:package-variant-closed-remove
icon_color: red
badge_icon: mdi:delete
layout: horizontal
multiline_secondary: false
tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.popup
data:
title: Excluir Rastreio
right_button: Excluir
right_button_action:
service: input_button.press
data:
entity_id: input_button.correios_excluir
content:
type: entities
entities:
- entity: input_select.rastreio
name: Qual o Código de Rastreamento?
icon: mdi:package-variant-closed
card_mod:
style: |
ha-card {
height: 200px !important;
}
card_mod:
style: |
ha-card {
--ha-card-background: white;
}
- type: custom:button-card
layout: icon_name
name: Objetos Cadastrados
icon: mdi:package-variant-closed
styles:
grid:
- grid-template-areas: '"n i"'
- grid-template-columns: 1fr 20%
icon:
- align-self: end
- color: var(--text-primary-color)
- height: 35px
card:
- padding: 4px
- height: 40px
- background: var(--primary-color)
name:
- color: var(--text-primary-color)
- justify-self: start
- padding-left: 10%
- font-weight: 400
- font-size: 18px
- type: custom:auto-entities
card:
type: grid
columns: 1
square: false
card_param: cards
show_empty: false
filter:
include:
- entity_id: sensor.correios_*
options:
type: custom:mushroom-template-card
card_mod:
style: |
ha-card {
--ha-card-background: white ;
}
entity: this.entity_id
primary: '{{ state_attr(''this.entity_id'', ''friendly_name'') }}'
secondary: >-
{% if states['this.entity_id'].state == '[]' %} Objeto aguardando
postagem nos Correios. {% elif states['this.entity_id'].state ==
"[{}]" %}Sincronizando com sistema dos correios {% else
%} {{ state_attr('this.entity_id', 'status')|join()
}}
{{ state_attr('this.entity_id', 'data')|join() }}
{{ state_attr('this.entity_id', 'local')|join() }}
{{ state_attr('this.entity_id', 'destino')|join() }}
{% endif %}
icon: >-
{% if states['this.entity_id'].state == "['Objeto entregue ao
destinatário']" %} mdi:package-variant-closed-check {% elif
states['this.entity_id'].state == "['Objeto entregue ao
remetente']"%} mdi:package-variant-closed-check {% elif
states['this.entity_id'].state == "['Objeto postado']"%}
mdi:store-plus {% elif states['this.entity_id'].state == "[]"
%}mdi:package-variant-closed-remove {% elif
states['this.entity_id'].state == "[{}]" %}mdi:refresh {% elif
states['this.entity_id'].state == "['Objeto saiu para entrega ao
destinatário']" %}mdi:human-dolly {% elif
states['this.entity_id'].state == "['Objeto está em rota de
entrega']" %}mdi:human-dolly {% elif
states['this.entity_id'].state == "['Objeto recebido pelos
Correios do Brasil']" %}mdi:flag-variant {% elif
states['this.entity_id'].state == "['Objeto em trânsito - por
favor aguarde']" %}mdi:truck {% endif %}
icon_color: >-
{% if states['this.entity_id'].state == "['Objeto entregue ao
destinatário']" %}green {% elif states['this.entity_id'].state
== "[]" %}red {% elif states['this.entity_id'].state == "[{}]"
%}red {% elif states['this.entity_id'].state == "['Objeto saiu
para entrega ao destinatário']" %}orange {% elif
states['this.entity_id'].state == "['Objeto está em rota de
entrega']" %}orange {% elif states['this.entity_id'].state ==
"['Objeto entregue ao remetente']" %}black {% elif
states['this.entity_id'].state != "['Objeto entregue ao
destinatário']" %}yellow {% endif %}
multiline_secondary: true
badge_icon: >-
{% if states['this.entity_id'].state == "['Objeto entregue ao
destinatário']" %}mdi:check-bold {% elif
states['this.entity_id'].state == "['Objeto postado']"
%}mdi:share {% elif states['this.entity_id'].state == "['Objeto
entregue ao remetente']" %}mdi:share {% elif
states['this.entity_id'].state == "[]" %}mdi:alert-box {% elif
states['this.entity_id'].state == "['Objeto saiu para entrega ao
destinatário']" %}mdi:share {% elif states['this.entity_id'].state
== "['Objeto está em rota de entrega']" %}mdi:share {% elif
states['this.entity_id'].state == "['Objeto recebido pelos
Correios do Brasil']" %}mdi:map-marker {% elif
states['this.entity_id'].state == "['Objeto em trânsito - por
favor aguarde']" %}mdi:share {% endif %}
badge_color: >-
{% if states['this.entity_id'].state == "['Objeto entregue ao
destinatário']" %}green {% elif states['this.entity_id'].state ==
"['Objeto entregue ao remetente']" %}green {% elif
states['this.entity_id'].state != "['Objeto entregue ao
destinatário']" %}grey {% endif %}
tap_action:
action: more-info
order_by:
last_changed: asc
sort:
method: last_changed
count: 10
reverse: true