First, if this isnt the right forum, please educate me and Ill delete/move it. I’m looking to add a sensor to my house, that when a line is broken, it turns on lights, etc through home assistant. Motion won’t work in this case as there are several things moving all the time in that portion of the house. Any ideas on what can be used? Pi? Arduino? I’m not sure where to even start looking.
I have something similar set up using a (kind of expensive) laser distance measurement sensor.
if the distance falls below the setpoint it’s internal 24vdc output turns off, turning off a relay that removes 3.3vdc from a GPIO of a nodemcu board that is integrated into HA via MQTT.
the expensive part is the laser device but you might be able to find one that does the equivalent function cheaper somewhere. I just had one laying around I could use.
Hi
My garage is very small and is quite common that the car is parked 4cm away from the folded iron door…
Sometimes I park the car and it is not away from the movement area of the garage door, so I have to return to the car, and rear it 2 or 3 cm more.
So, I need to “built a line/wall”, that if it is interrupted the car is not on a safe position and it would turn on a few RED LEDs, when in safe position it would turn on a few GREEN LEDs.
I find this laser optic sensor, that says it would work up to 6m. My garage door have 5m. https://de.aliexpress.com/item/1005005382850864.html?spm=a2g0o.cart.0.0.60f64ae4a2rfZT&mp=1&gatewayAdapt=glo2deu
@finity can you share the yaml that you use on ESPHome? What about the wiring?
About the laser optic sensor that I found, would I go for NPN or PNP? NO or NC?
Does anyone recommend other solution?
Thanks in advance!
$2 ToF maybe? Makes even the reflector obsolete.
I don’t use ESPHome for that sensor. It’s written using ArduinoIDE. I can post that code if you’d like.
I’m sure you can do the same in ESPHome but I made this sensor a long time back before ESPHome was popular, maybe even before it existed.
Here is the arduino code:
/* Relay Module interface
connect VCC to the same power supply positive as your laser (5vdc in my example case)
connect GND to the 5vdc power supply negative
connect IN to the output of your laser
Connect NO output of relay to whatever your Button Pin is (D2)
Connect common input of relay to 3.3v pin
Connect a 10K resistor from Button Pin (D2) to GROUND
*/
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <PubSubClient.h>
// what digital pin we're connected to NodeMCU (D2)
#define BUTTON D2
//turns on onboard LED
#define LED D0
//Wifi Network Setup
#define wifi_ssid "your_wifi_ssid"
#define wifi_password "your_wifi_password"
//MQTT Network Setup
#define mqtt_server "your_mqtt_broker_ip"
#define mqtt_user "your_mqtt_user"
#define mqtt_password "your_mqtt_password"
//MQTT Topic Setup
// change below to be unique for each sensor
#define clientName "PEsensorEAST"
#define beam_topic "PEsensorEAST/state"
WiFiClient espClient;
PubSubClient client(espClient);
int BUTTONstate = 0;
void setup() {
pinMode (BUTTON, INPUT);
pinMode (LED, OUTPUT);
digitalWrite(BUTTONstate, LOW);
digitalWrite(LED, HIGH);
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
}
String macToStr(const uint8_t* mac)
{
String result;
for (int i = 0; i < 6; ++i) {
result += String(mac[i], 16);
if (i < 5)
result += ':';
}
return result;
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifi_ssid);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection…");
Serial.print("Connecting to ");
Serial.print(mqtt_server);
Serial.print(" as ");
Serial.println(clientName);
// Attempt to connect
if (client.connect(clientName, mqtt_user, mqtt_password))
{
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
checkConnection();
delay(1000);
if (!client.connected()) {
reconnect();
}
client.loop();
BUTTONstate = digitalRead(BUTTON);
if (BUTTONstate == HIGH)
{
Serial.println("Beam Broken!");
digitalWrite(LED, LOW);
client.publish(beam_topic, "OFF");
}
else
{
Serial.println("Beam OK");
digitalWrite(LED, HIGH);
client.publish(beam_topic, "ON");
}
}
void checkConnection() {
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connection . . . . . . . . . . LOST");
ESP.restart();
}
}
here is the schematic (from memory so I could be mistaken on the details):
you will need to find a relay rated for the voltage of the laser power supply instead of the 5vdc I used in the example.
substitute your laser detector output for the switch S1.
Thanks for the tip, but I need it to work on 5meters, these sensor don’t go so far…
Mind to share the size of your garage?
Often there is a mathematical approach in solving this. Two things come to my mind already. Obvious one is to have two ToF’s - one on each side. In the middle might a blind spot of around one meter but that should only be a problem if you have a car with less than 1 meter of width () and like to park in in the very middle
Beside you could also mount one (or more) ToF’s on the spot in front of your car and let do math (directly in esphome) do the trick to tell/indicate the distance to the door
Hi @orange-assistant, I don’t mind.
I can do that during the afternoon, I also like maths and methodic approach but I’m married… And she is a bug chaser… And if she doesn’t find a bug, she just reply “because I thing this way is better”…
Not quite your use case I guess but just as an example for car presence and a (rough) position detection with ultra sonic sensors
Great tutorial, but, as you said, “rough position” for my case.
So…
did the info that you asked for and I posted help at all?
What about using the beam-break sensors from garage door openers? With an ESP8266, you should be able to prepare something rather quickly.
https://www.homedepot.com/p/Genie-Safe-T-Beam-Garage-Door-Safety-Sensors-Replacement-Kit-for-Genie-Garage-Door-Openers-GSTB-R/202808538#overlay