Skip to content

Instantly share code, notes, and snippets.

@jeffehobbs
Last active June 5, 2024 15:53
Show Gist options
  • Save jeffehobbs/93ab682705ec3bbba19887903e7ccdb9 to your computer and use it in GitHub Desktop.
Save jeffehobbs/93ab682705ec3bbba19887903e7ccdb9 to your computer and use it in GitHub Desktop.
Vibration Sensor for ESPHome/Home Assistant
GOAL: Send a push notification after the (vibrations from the) dryer cycle has completely stopped.
USING:
* Inexpensive hardware (see below)
* ESPhome (http://esphome.io) for chip firmware
* Home Assistant (http://hass.io) for sensor state machine and push notification.
---
SHOPPING LIST:
ESP32 DEV BOARD:
https://www.amazon.com/gp/product/B079PVCF2G/
SW-420 VIBRATION SENSOR:
https://www.amazon.com/gp/product/B06XHFFPL6/
MICRO USB POWER SUPPLY:
https://www.amazon.com/gp/product/B00MARDJZ4/
3 FEMALE-TO-FEMALE JUMPER WIRES:
https://www.amazon.com/gp/product/B07GD2BWPY/
MOUNTING TAPE:
https://www.amazon.com/Scotch-Mounting-5-Inch-75-Inch-2-PACK/dp/B00SJ6HA7S/
CASE:
https://www.amazon.com/gp/product/B07G8S6XLV/
---
SETUP:
1) Create new text file, espvibration1.yaml
2) Place in file the following YAML, customizing the "ssid" and "password" values:
# Names and defines the hardware
esphome:
name: espvibration1
platform: ESP32
board: nodemcu-32s
# Defines WiFi network/password
wifi:
ssid: "YOUR WIFI NETWORK"
password: "YOUR WIFI PASSWORD"
# Enables logging via console
logger:
# Enables Home Assistant API, pushes sensor state back to Home Assistant
api:
# Enables over-the-air firmware updates
ota:
# Sensors that the ESPhome unit is capable of reporting
sensor:
- platform: wifi_signal
name: "ESPVibration1 WiFi Signal"
update_interval: 60s
- platform: uptime
name: "ESPVibration1 Uptime"
update_interval: 60s
# Enables status LED
status_led:
pin: GPIO2
# Enables the SW-420 Vibration Sensor
binary_sensor:
- platform: gpio
name: "Dryer"
pin:
number: GPIO13
mode: INPUT
device_class: vibration
filters:
- delayed_on: 10ms
- delayed_off: 5min
3) Upload espvibration1.yaml to ESP32 dev board ("esphome espvibration1.yaml run").
4) Connect the vibration sensor to the ESP32 dev board using jumper wires:
a) Connect "VCC" on the SW-420 to the pin labeled "3V3" on the ESP32.
b) Connect "GND" (ground, center pin) on the SW-420 to the pin labeled "GND" on the ESP32.
c) Connect "D" on the SW-420 to pin "D13" on the ESP32.
NOTE: Feel free, if you are confident, to solder those jumpers in when successfully tested.
5) Drill small hole in case for power supply.
6) Place vibration sensor in case with mounting tape.
7) Place ESP32 board into case.
8) Stick case to object to be monitored with mounting tape.
9) Power up the ESP32.
10) In the Home Assistant web UI, go to "Configurations > Integrations". Activate the newly discovered "espvibration1".
11) In automations.yaml, add the following code:
- id: 'espvibration1'
alias: Dryer Done
trigger:
- entity_id: binary_sensor.dryer
from: 'on'
platform: state
to: 'off'
condition: []
action:
- data:
message: The dryer is done.
service: notify.ios_iphone
NOTE: Substitute the Home Assistant service ("notify.ios_iphone") that applies to your favored notification.
12) Reload your automations. You should now get a push notification 15 seconds after the dryer is finished.
13) Adjust the "delayed_off" value in the ESPHome code to account for your dryer's particular cycle, to avoid false positives.
@distante
Copy link

Hi @jeffehobbs Do you have the exact models you used here? like which esp32 board model. Since some of the links do not work anymore.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment