Skip to content

Action Buttons

Calin Crisan edited this page Apr 24, 2016 · 3 revisions

What Are Action Buttons?

Starting with version 20151230, motionEyeOS can be configured to overlay buttons on top of a camera frame. These buttons will then execute custom commands when clicked.

Action buttons are particularly useful when you need to turn on/off the light next to a camera or trigger an alarm when you see an intruder entering the camera's field of view.

For more details on available actions and how they work, see the motionEye article on Action Buttons.

Enabling Actions

You'll need to decide which of the available actions is the closest to your needs. Then, using an SSH client, log in remotely to your motionEyeOS and create the corresponding file in /data/etc/, using nano.

Simple GPIO Example

Let's say that you want to turn on a light bulb that's controlled via GPIO number 18 on a Raspberry PI, when you click on the "turn light on" action button of your first camera (with id 1). Create the following bash script:

nano /data/etc/light_on_1

Then type in (or paste) the following contents, save and exit nano (Ctrl-O, Enter, Ctrl-X):

#!/bin/bash

GPIO=18
test -e /sys/class/gpio/gpio$GPIO || echo $GPIO > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$GPIO/direction
echo 1 > /sys/class/gpio/gpio$GPIO/value

Don't forget to make the script executable:

chmod +x /data/etc/light_on_1

Similarly, to turn off your light bulb, create a file called /data/etc/light_off_1 and change echo 1 > ... to echo 0 > ....

HTTP Request Example

Let's say now that you want to issue an HTTP request to a certain URL when you click the "turn alarm on" button of your second camera (with id 2). Create the following bash script:

nano /data/etc/alarm_on_2

Then type in (or paste) the following contents, save and exit nano (Ctrl-O, Enter, Ctrl-X):

#!/bin/bash

URL="http://192.168.1.123/webhook/alarm/"
METHOD="POST"
TIMEOUT="5"
curl -X $METHOD --connect-timeout $TIMEOUT "$URL" > /dev/null

Don't forget to make the script executable:

chmod +x /data/etc/alarm_on_2