Fala Moçada!
A quem interessar, compartilho aqui um Fluxo do NODE-RED para dar aquela MORAL em DATAS IMPORTANTES com a pessoa amada!
Basicamente o fluxo consiste em verificar se estamos em um DIA ESPECÍFICO no MÊS (ou 12/Julho) bem como as 06:00 da manhã e liga algumas luzes (LEDs e LUZES) na cor VERMELHO () para indicar que aquele dia especial (Dia de maldade!? Não, pô! Dia de comprar uma flor para o ente querido! )
Vamos lá…
Aqui temos um INJECT NODE que roda TODO DIA as 06:00 da manhã…
No meu caso, verifico o dia 13, pois é o DIA do meu casamento. Portanto, troque para o DIA que representar algo para você.
Lógica:
let d = new Date();
if (d.getDate() == 13)
{
msg.payload = “on”;
return msg;
}
return null;
Além disso, verifico também se é dia 12/Julho (Dia dos Namorados). Percebam que ao invés de verificar se é mês 6, tive que colocar como 5 pois começa com 0 (Janeiro).
Lógica:
let d = new Date();
if (d.getDate() == 12 && d.getMonth() == 5)
{
msg.payload = “on”;
return msg;
}
return null;
Em seguida verifico se a LUZ que quero acender está DESLIGADA. No campo Entity Id coloque o nome da SUA luz.
Aí ligo a luz na cor VERMELHO…
Lógica:
{
“color_name”: “red”
}
Veja que aqui coloquei um DELAY de 5s e ligo novamente a luz na cor VERMELHO. Fiz isso para ter um “backup” caso na primeira tentativa de ligar o wifi oscile e não seja possível ligar e trocar e cor. Daí isso faz com que seja chamado novamente a ligação e troque para a cor VERMELHO.
Segue o código do Fluxo a ser importado pelo Clipboard:
[{"id":"deb3c660.01f708","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"9bb2297e.451178","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LUZES MESA VERMELHO","server":"ef4eb39d.410e6","version":1,"service_domain":"light","service":"turn_on","entityId":"light.mesa","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":40,"wires":[["af77a244.b2da4"]]},{"id":"53084867.449298","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LEDS SALA VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.leds_sala","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":100,"wires":[["71a04cd5.d84f74"]]},{"id":"3f61831c.7c6b0c","type":"function","z":"deb3c660.01f708","name":"DIA 13?","func":"let d = new Date();\nif (d.getDate() == 13) \n{\n\tmsg.payload = \"on\";\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"x":300,"y":100,"wires":[["a3748aaf.b41af8","4faa824f.71667c","d7beed08.48513","79c8084b.7d1df8"]]},{"id":"cbbeb42b.0a9948","type":"inject","z":"deb3c660.01f708","name":"06:00","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 06 * * *","once":false,"onceDelay":0.1,"x":90,"y":40,"wires":[["3f61831c.7c6b0c","8c0806c2.20e8a8"]]},{"id":"a3748aaf.b41af8","type":"api-current-state","z":"deb3c660.01f708","name":"LUZES MESA DESLIGADAS?","server":"ef4eb39d.410e6","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.mesa","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":570,"y":40,"wires":[["9bb2297e.451178"],[]]},{"id":"4faa824f.71667c","type":"api-current-state","z":"deb3c660.01f708","name":"LEDS SALA DESLIGADOS?","server":"ef4eb39d.410e6","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.leds_sala","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":100,"wires":[["53084867.449298"],[]]},{"id":"8c0806c2.20e8a8","type":"function","z":"deb3c660.01f708","name":"DIA DOS NAMORADOS?","func":"let d = new Date();\nif (d.getDate() == 12 && d.getMonth() == 5) \n{\n\tmsg.payload = \"on\";\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"x":250,"y":140,"wires":[["a3748aaf.b41af8","4faa824f.71667c","d7beed08.48513","79c8084b.7d1df8"]]},{"id":"dfa6ca38.28b7b8","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LEDS SUÍTE VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.leds_suite","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":160,"wires":[["8c353c62.d2b61"]]},{"id":"d7beed08.48513","type":"api-current-state","z":"deb3c660.01f708","name":"LEDS SUÍTE DESLIGADOS?","server":"ef4eb39d.410e6","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.leds_suite","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":160,"wires":[["dfa6ca38.28b7b8"],[]]},{"id":"ccba5b89.7836a8","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LEDS SALA VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.leds_sala","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1310,"y":100,"wires":[[]]},{"id":"71a04cd5.d84f74","type":"delay","z":"deb3c660.01f708","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1100,"y":100,"wires":[["ccba5b89.7836a8"]]},{"id":"8c353c62.d2b61","type":"delay","z":"deb3c660.01f708","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1100,"y":160,"wires":[["e2727c3f.ec724"]]},{"id":"e2727c3f.ec724","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LEDS SUÍTE VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.leds_suite","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":160,"wires":[[]]},{"id":"af77a244.b2da4","type":"delay","z":"deb3c660.01f708","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1100,"y":40,"wires":[["927a2e5.af8d2d"]]},{"id":"927a2e5.af8d2d","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LUZES MESA VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.table","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":40,"wires":[[]]},{"id":"5594f7e8.33b3d8","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LUZ ESCADA VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.escada","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":220,"wires":[["7d7558a2.d5ed18"]]},{"id":"79c8084b.7d1df8","type":"api-current-state","z":"deb3c660.01f708","name":"LUZ ESCADA DESLIGADA?","server":"ef4eb39d.410e6","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.escada","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":220,"wires":[["5594f7e8.33b3d8"],[]]},{"id":"7d7558a2.d5ed18","type":"delay","z":"deb3c660.01f708","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1100,"y":220,"wires":[["ed1a91d3.626c6"]]},{"id":"ed1a91d3.626c6","type":"api-call-service","z":"deb3c660.01f708","name":"LIGAR LUZ ESCADA VERMELHO","server":"ef4eb39d.410e6","version":"1","service_domain":"light","service":"turn_on","entityId":"light.escada","data":"{\"color_name\":\"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":220,"wires":[[]]},{"id":"ef4eb39d.410e6","type":"server","z":"","name":"Home Assistant"}]
Um post cheio de amor para vocês!
Abraços,
José Henrique.