Thought I’d share this project because it’s been very successful at encouraging the numerous stray cats in my suburb from coming into my yard at night and pissing on everything and anything, causing foul stink, and house & car damage (cat pee strips off paint and zinc metal coatings if done often enough).
We have our own cats too, so the system has to deactivate (via HA automation) during day light hours when our cats are allowed outside.
The unit squirts commercial party silly string at the cats, which scares them away but causes no physical harm. They don’t seem to come back…
The build consists of a 3D printed ABS plastic RC servo spray can adapter (STL file from Thingiverse.com), an ESP32 board, a servo (obviously), a AM312 Infrared motion sensor (same as used in the Bruh Automation Multi Sensor project), a mini SPST switch, a couple of LEDs and 0.5k resistors, a small project box etc. Additionally I home printed a tall ring go block the side vision of the AM312 to get a narrow detection angle from it.
It operates by sitting outside in the yard in an area where the stray cats piss regularly, and is only armed at night by HA (don’t want to scare the meter reader or postman do I !). When a hot object is detected by the AM312 the ESPhome code check that the manual ARM switch on the back of the box is ON, then also checks if the HA remote blocking is OFF (off at night), then squirts 0.7 seconds of silly string by moving the servo by a set amount and back. The code gives the operator 10 seconds to clear out once the local arm switch is thrown, HA can block anyway and the final ARM be done remotely if wanted.
The wiring can be worked out from the ESPhome devices YAML file, it’s nothing special.
The pictures will tell the story best I hope.
esphome:
name: servo_actuator_1
platform: ESP32
board: esp32doit-devkit-v1
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# Create Status LED using the ESP32 blue LED
status_led:
pin: GPIO2
sensor:
- platform: wifi_signal
name: "Servo actuator #1 WiFi Signal Sensor"
update_interval: 60s
binary_sensor:
- platform: status
name: "Servo actuator #1 Status"
- platform: gpio
pin: GPIO23
name: "Servo actuator #1 Motion"
device_class: motion
on_press:
then:
if:
condition:
and:
- binary_sensor.is_on: esp32_arm_switch
- switch.is_off: ha_remote_arm_switch
then:
- output.turn_on: yellow_led
- output.set_level:
id: gpio_21_servo
level: 100.0% # 100% = 2mS as set by 'max_power'
- delay: 700ms
- output.set_level:
id: gpio_21_servo
level: 0.0% # 0% = 1mS as set by 'min_power'
else:
- output.turn_on: yellow_led
on_release:
then:
- output.turn_off: yellow_led
- output.set_level:
id: gpio_21_servo
level: 0.0% # 0% = 1mS as set by 'min_power'
- platform: gpio
pin: GPIO18
name: "Control Board Arm Switch"
id: esp32_arm_switch
device_class: safety # ...
filters:
- delayed_on: 10000ms
on_press:
then:
- output.turn_on: yellow_led
- delay: 1500ms
- output.turn_off: yellow_led
# Using Light component to set a standard RC servo position
light:
- platform: monochromatic
output: gpio_21_servo
name: "Servo actuator #1 - Servo Pos"
default_transition_length: 0ms
#create a logical switch that HA can control
switch:
- platform: output
name: "HA Remote Arm Switch"
output: 'green_led'
id: ha_remote_arm_switch
# Using ledc output to control a standard 50Hz RC servo over the normal 1 to 2 mS pulse range
output:
- platform: ledc
pin: GPIO21
id: gpio_21_servo
frequency: 50 Hz
min_power: 5.0% # 5% at 50Hz is 1mS (20mS cycles)
max_power: 10.0% # 10% at 50Hz is 2mS (20mS cycles)
- platform: gpio
pin: GPIO15
inverted: false
id: yellow_led
- platform: gpio
pin: GPIO19
inverted: false
id: green_led
In HA lovelace frontend I’ve renamed the switches and sensors to something more fitting to the task.