Nesse tutorial, eu mostro como você pode criar um sensor de estacionamento com um ESP8266 e um sensor ultrassônico integrado ao Home Assistant.
- Produtos recomendados para uso com Home Assistant:
🔸 Wemos D1 Mini (ESP8266): https://s.click.aliexpress.com/e/_9vB7mA
🔸 Sensor Ultrassônico: https://s.click.aliexpress.com/e/_A9AYlg
🔸 Sensor Ultrassônico Resistente a água: https://s.click.aliexpress.com/e/_ACpGEi
🔸 Case de plástico (utilizei style 2-black): https://s.click.aliexpress.com/e/_AEDFTu
2. Esquema de Ligação Wemos D1 Mini e Sensor Ultrassônico:
3. Código ESPHOME:
substitutions: nome: garagem-ultrasonico-01 nome_completo: Garagem UltraSonico 1 esphome: name: $nome platform: ESP8266 board: d1_mini wifi: ssid: !secret ssid password: !secret wifi_senha ap: ssid: "Esphome ${nome_completo}" password: !secret wifi_senha logger: ota: password: "senhaota" api: captive_portal: sensor: - platform: ultrasonic trigger_pin: GPIO1 echo_pin: GPIO3 name: "Garagem 01" update_interval: 2s icon: "mdi:car-connected" switch: - platform: restart name: "Restart ${nome_completo}"
3. Nó NodeRED:
[{"id":"d88ed9febb84ceba","type":"server-state-changed","z":"cbe13f70d0678e15","name":"Garagem 01","server":"27f1aa3c.860de6","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.garagem_01","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":110,"y":120,"wires":[["263c07fef1786c17"]]},{"id":"d17c2a627630ad4b","type":"switch","z":"cbe13f70d0678e15","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"str"},{"t":"btwn","v":"0.5","vt":"num","v2":"1","v2t":"num"},{"t":"btwn","v":"0.5","vt":"num","v2":"0.2","v2t":"num"},{"t":"lte","v":"0.2","vt":"num"},{"t":"lte","v":"0.1","vt":"num"}],"checkall":"true","repair":false,"outputs":5,"x":310,"y":240,"wires":[["0dc394dc34c6749a"],["3a61198eb8fe9260"],["423c8db25060f37d"],["9472eb28252fd2cd"],["8f4938ebd647acf1"]]},{"id":"f38f559d0f6f4019","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Verde","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.led_janela","data":"{ \"color_name\": \"green\" }","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":240,"wires":[[]]},{"id":"53acbad82762005a","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Vermelha","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.led_janela","data":"{\"color_name\":\"red\", \"flash\": \"short\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":660,"y":360,"wires":[[]]},{"id":"021fb5de398085c8","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Amarela","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.led_janela","data":"{ \"color_name\": \"yellow\" }","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":650,"y":300,"wires":[[]]},{"id":"ab371b7eb041b085","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Branca","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.led_janela","data":"{\"color_name\":\"white\",\"flash\":\"short\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":650,"y":180,"wires":[[]]},{"id":"bc8dfd3285711e12","type":"api-call-service","z":"cbe13f70d0678e15","name":"Volume Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"number","service":"set_value","entityId":"number.garagem_sirene_volume","data":"{\"value\":60}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":440,"wires":[["0e5eabd928d4eabd"]]},{"id":"0e5eabd928d4eabd","type":"api-call-service","z":"cbe13f70d0678e15","name":"Liga Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.garagem_sirene_alarm","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":440,"wires":[["59803c74a0c3b728"]]},{"id":"59803c74a0c3b728","type":"delay","z":"cbe13f70d0678e15","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1000,"y":440,"wires":[["4968b8dbe83aa5c3"]]},{"id":"4968b8dbe83aa5c3","type":"api-call-service","z":"cbe13f70d0678e15","name":"Desliga Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.garagem_sirene_alarm","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1180,"y":440,"wires":[["d3cb95434b49ecd2"]]},{"id":"d3cb95434b49ecd2","type":"api-call-service","z":"cbe13f70d0678e15","name":"Estacionado On","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.estacionado1","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1380,"y":440,"wires":[["78d7ba8d2c47b4e4"]]},{"id":"263c07fef1786c17","type":"api-current-state","z":"cbe13f70d0678e15","name":"Estacionado?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.estacionado1","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":140,"y":240,"wires":[["d17c2a627630ad4b"],["72404478898343eb"]]},{"id":"5b8ab32814a51573","type":"api-call-service","z":"cbe13f70d0678e15","name":"Estacionado Off","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.estacionado1","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":340,"y":40,"wires":[["93a5279a97143f9a"]]},{"id":"4e7fc64aa24441f5","type":"api-call-service","z":"cbe13f70d0678e15","name":"Liga Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.garagem_sirene_alarm","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":40,"wires":[["674f8c5942e6a898"]]},{"id":"674f8c5942e6a898","type":"delay","z":"cbe13f70d0678e15","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1040,"y":40,"wires":[["26c511e5c188fa49"]]},{"id":"26c511e5c188fa49","type":"api-call-service","z":"cbe13f70d0678e15","name":"Desliga Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.garagem_sirene_alarm","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1220,"y":40,"wires":[["1a1a3dbc3717cfe7"]]},{"id":"174efb90e991bce3","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Off","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.led_janela","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1720,"y":440,"wires":[[]]},{"id":"78d7ba8d2c47b4e4","type":"delay","z":"cbe13f70d0678e15","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1560,"y":440,"wires":[["174efb90e991bce3"]]},{"id":"72404478898343eb","type":"switch","z":"cbe13f70d0678e15","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":120,"wires":[["5b8ab32814a51573"]]},{"id":"87189c4af29edccd","type":"api-call-service","z":"cbe13f70d0678e15","name":"Luz Off","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.led_janela","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1560,"y":40,"wires":[[]]},{"id":"1a1a3dbc3717cfe7","type":"delay","z":"cbe13f70d0678e15","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1400,"y":40,"wires":[["87189c4af29edccd"]]},{"id":"8f4938ebd647acf1","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":470,"y":440,"wires":[["bc8dfd3285711e12"],["298a457276f04b63"]]},{"id":"298a457276f04b63","type":"api-call-service","z":"cbe13f70d0678e15","name":"Volume Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"number","service":"set_value","entityId":"number.garagem_sirene_volume","data":"{\"value\":10}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":480,"wires":[["0e5eabd928d4eabd"]]},{"id":"a3082a3e88483b0b","type":"api-call-service","z":"cbe13f70d0678e15","name":"Volume Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"number","service":"set_value","entityId":"number.garagem_sirene_volume","data":"{\"value\":60}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":680,"y":40,"wires":[["4e7fc64aa24441f5"]]},{"id":"93a5279a97143f9a","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":510,"y":40,"wires":[["a3082a3e88483b0b"],["e65f40854abd3be1"]]},{"id":"e65f40854abd3be1","type":"api-call-service","z":"cbe13f70d0678e15","name":"Volume Sirene","server":"27f1aa3c.860de6","version":3,"debugenabled":false,"service_domain":"number","service":"set_value","entityId":"number.garagem_sirene_volume","data":"{\"value\":10}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":680,"y":80,"wires":[["4e7fc64aa24441f5"]]},{"id":"0dc394dc34c6749a","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":490,"y":180,"wires":[["a3082a3e88483b0b"],["ab371b7eb041b085"]]},{"id":"3a61198eb8fe9260","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":490,"y":240,"wires":[[],["f38f559d0f6f4019"]]},{"id":"423c8db25060f37d","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":490,"y":300,"wires":[[],["021fb5de398085c8"]]},{"id":"9472eb28252fd2cd","type":"api-current-state","z":"cbe13f70d0678e15","name":"Dia?","server":"27f1aa3c.860de6","version":3,"outputs":2,"halt_if":"above_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload_sun","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":490,"y":360,"wires":[[],["53acbad82762005a"]]},{"id":"27f1aa3c.860de6","type":"server","name":"HA","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]