Im really proud of myself. not a programmer but I managed to put this together using esphome, an analog vibration sensor, mp3 module and neopixel strip. The only issue seems to be the colors. Im not getting blue and red. Im just getting white. Also not sure how sensitive I should make the vibration sensor. I havent used in yet in the real world so I dont know what im up against either.
separately, I have an RFID tag that turns on a relay (my electric bike).
I need help with one last thing. I only want the alarm to work when the relay is on. Can someone help me with that code.
Any improvements on the code or setup appreciated.
esphome:
name: moped-test
platform: ESP8266
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifissid
password: !secret wifipass
manual_ip:
static_ip: 192.168.1.47
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Moped-Test Fallback Hotspot"
password: "MpLi4BNmRnqs"
captive_portal:
web_server:
port: 80
# Example configuration entry
# light:
# - platform: neopixelbus
# type: GRB
# pin: GPIO3
# num_leds: 60
# name: "NeoPixel Light"
# Configure each pixel as a single light (attention memory consuming)
light:
- platform: fastled_clockless
chipset: WS2812B
id: light_fastled
pin: D8
num_leds: 10
rgb_order: GRB
name: "Infostrip"
effects:
- strobe:
- strobe:
name: Strobe Effect With Custom Values
colors:
- state: true
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 500ms
- state: false
duration: 250ms
- state: true
brightness: 100%
red: 0%
green: 0%
blue: 100%
duration: 500ms
uart:
tx_pin: GPIO1
# rx_pin: GPIO3
baud_rate: 9600
# Declare DFPlayer mini module
dfplayer:
on_finished_playback:
then:
logger.log: 'Somebody press play!'
sensor:
- platform: adc
pin: A0
name: "moped vibration"
id: moped_vibration
update_interval: 0.5s
on_value:
then:
- if:
condition:
sensor.in_range:
id: moped_vibration
above: 0.02
below: 1.0
then:
- dfplayer.play_folder:
folder: 1
file: 1
- light.turn_on:
id: light_fastled
effect: strobe
- delay: 3s
- light.turn_off:
id: light_fastled
switch:
- platform: gpio
name: "Moped Relay test"
pin:
number: D4
# inverted: yes
id: relay
spi:
clk_pin: D5
miso_pin: D7
mosi_pin: D6
rc522_spi: # or rc522_i2c
cs_pin: D0
update_interval: 1s
binary_sensor:
- platform: rc522
uid: FC-41-0C-4A
name: "RC522 RFID Moped Tag1"
on_press:
then:
- switch.toggle: relay
- platform: rc522
uid: 93-D9-B9-18
name: "RC522 RFID Moped Tag2"
on_press:
then:
- switch.toggle: relay
- platform: rc522
uid: 5C-7F-0A-49
name: "RC522 RFID Moped Tag3"
on_press:
then:
- switch.toggle: relay
- platform: rc522
uid: 13-66-89-1A
name: "RC522 RFID Moped Tag4"
on_press:
then:
- switch.toggle: relay