When PIR sensor detects movement it sends message to Radio Dongle plugged to the Raspberry Pi which sends the message to the MQTT server. On the other side MQTT message is processed by the Home Assistant which then using the automation triggers smart plug and starts configured countdown.
Radio DongleIn my deployment, I wanted to reuse old Raspberry Pi 1 Model B Rev 2 for the BigClown Radio Dongle, which was quite challenging as the standard installation was not supported on this particular old version of Pi. So plan B was needed - manally install only what is needed.
# Install Python
apt install python3 python3-pip python3-setuptools
pip3 install --upgrade pip
# Install BigClown tooling
pip3 install --upgrade bcf bcg bch
When we have needed tools ready, let's create udev rule for the dongle:
echo 'SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="ttyUSB*", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6015", ATTRS{serial}=="bc-usb-dongle*", SYMLINK+="bcUD%n", TAG+="systemd", ENV{SYSTEMD_ALIAS}="/dev/bcUD%n"' | sudo tee --append /etc/udev/rules.d/58-bigclown-usb-dongle.rules
After the RPi restart Radio Dongle should be properly detected now:
# ls /dev/bc*/dev/bcUD0
Now we can start gateway and start submitting the MQTT messages to the broker:
/usr/local/bin/bcg --device /dev/bcUD0 --mqtt-host 10.10.10.10
Motion Detector
My Motion Detector kit came with the default firmware already loaded and by default, the module sends updates every time the motion is detected, but not more often than 1 minute. Which is fine for my intended use, but if you would like to adjust the threshold, default firmware is available on Github at repository https://github.com/bigclownlabs/bcf-radio-motion-detector and in file app/application.c
value of PIR_PUB_MIN_INTEVAL
needs to be adjusted accordingly. Firmware flashing process if thoroughly described in the documentation.
I've chosen the tp-link HS110 as it can be remotely controlled via Home Assistant without any cloud account needed but anything can be used to control the power. Other option would be to use BigClown's Relay Module (https://shop.bigclown.com/relay-module/) and directly control the power of the water fountain, but I prefer the separate power control so I can move PIR sensor in the room freely, typically in the corridor, so the water would start flowing before the cat gets near the fountain :-)
Home AssistantThis is the excerpt of the configuration to support this scenario:
~/.homeassistant/configuration.yaml
mqtt:
broker: 10.10.10.10
port: 1883
switch:
- platform: tplink
host: 10.10.10.11
name: "Water Fountain"
sensor:
- platform: mqtt
state_topic: 'node/kit-motion-detector:0/pir/-/event-count'
name: 'Counter'
icon: mdi:smoke-detector
- platform: mqtt
state_topic: 'node/kit-motion-detector:0/battery/-/voltage'
name: 'Voltage'
unit_of_measurement: 'V'
input_number:
slider_water_fountain:
name: Timeout after PIR
initial: 15
min: 1
max: 60
step: 5
unit_of_measurement: min
automation:
- alias: Start Water Fountain by PIR
trigger:
platform: state
entity_id: sensor.counter
action:
service: switch.turn_on
entity_id: switch.water_fountain
- alias: Vypnutí fontány po pohybu
trigger:
platform: state
entity_id: sensor.counter
condition:
condition: and
conditions:
- condition: state
entity_id: switch.water_fountain
state: 'off'
action:
service: homeassistant.turn_on
entity_id: script.timed_water_fountain
script:
timed_water_fountain:
alias: "Set water fountain timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off_water_fountain
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off_water_fountain
timer_off_water_fountain:
alias: "Turn off water fountain"
sequence:
- delay: '00:{{ states.input_number.slider_water_fountain.state | int }}:00'
- service: homeassistant.turn_off
entity_id: switch.water_fountain
group:
bcpir:
name: 'PIR Sensor'
icon: mdi:smoke-detector
entities:
- sensor.voltage
- sensor.counter
fountain:
name: 'Water fountain'
entities:
- switch.water_fountain
- input_number.slider_water_fountain
- automation.start_water_fountain_by_pir
MQTT outputIf everything works, in MQTT you should soon see events sent by the BigClown Gateway from the Motion Detector like this:
# mosquitto_sub -h 10.10.10.10 -t "node/#" -v
node/kit-motion-detector:0/pir/-/event-count 28250
node/kit-motion-detector:0/pir/-/event-count 28253
node/kit-motion-detector:0/pir/-/event-count 28264
node/kit-motion-detector:0/pir/-/event-count 28279
node/kit-motion-detector:0/pir/-/event-count 28282
node/kit-motion-detector:0/pir/-/event-count 28311
node/kit-motion-detector:0/battery/-/voltage 2.91
node/kit-motion-detector:0/pir/-/event-count 28318
Home AssistantThis is how it looks in my Home Assistant instance, everything is controlled from one tab.
Comments