A little rough script to detect a washing machine/dryer load and alert you with Telegram or any other GET webhook when the load is over (multiple urls are supported). Useful when you don't hear the end of cycle sound. It uses the ADXL345 accelerometer with this convenient driver for raspberry pi (tested with raspberry pi 1).
Make sure you have a functional setup with the ADXL345 and that the sensor is anchored on the machine, ready to measure on the Z axis.
All the steps mentioned here should be executed on the raspberry pi.
- Clone the repository
- Copy the
adxl345.py
file in the same directory as the script OR - Add the driver path to your
PYTHONPATH
environment variable (export PYTHONPATH=$PYTHONPATH:/somedirectory/adxl345-python
)
- Clone the repository
- Run with
sudo ./time_to_fold_alerter.py https://api.telegram.org/botxxxx/sendMessage?chat_id=xxxxxx&text=Done https://otherwebhook.com
(sudo is required for writing to/var/log
)
On the first run, you can run with the -v
flag and this will output relevant information in the log file (/var/log/time_to_fold_alerter.py
) such as the maximum acceleration detected in the idle phase detection. You can also configure the idle threshold that is used to detect movement with the -i
flag.
Help is also available with python time_to_fold_alerter.py -h
:
$ ./time_to_fold_alerter.py -h
usage: time_to_fold_alerter.py [-h] [-v] [-i IDLE_THRESHOLD] [-a ADDRESS]
notification_urls [notification_urls ...]
Washing machine/dryer action detector. Logs are in
/var/log/time_to_fold_alerter.log.
positional arguments:
notification_urls the url to send the notification to via a GET
optional arguments:
-h, --help show this help message and exit
-v, --verbose run the program with debug logs
-i IDLE_THRESHOLD, --idle_threshold IDLE_THRESHOLD
the idle threshold for movement detection (default:
0.1)
-a ADDRESS, --address ADDRESS
the address of the adxl354 in int or hexadecimal,
useful when you use multiple sensors on the same board
(default: 0x53)
A SystemD script is supplied in the init-script
directory. To use it, modify the ExecStart
command to add the notification url and the optional arguments. Set the right permissions (sudo chmod 644 time-to-fold-alerter.service
) and copy the file in the /lib/systemd/system/
directory. Enable the service and reboot :
sudo systemctl daemon-reload
sudo systemctl enable time-to-fold-alerter.service
The script uses a very simple state machine since the pi is not really suitable for complex live FFT calculations. It uses the following algorithm :
- poll the sensor for 1 second each 10 seconds
- if output is higher than the configurable
idle_threshold
, increment a counter and repeat - if counter > 2, it means we have a load
- loop until the maximum acceleration is below the
idle_threshold
for 1 minute straight. - send notification
While the flow is not very elaborated, it's very reliable in my experience but might requires tuning for other machines as I've only tested with one.
Open an issue!