diff --git a/defaults/main.yml b/defaults/main.yml index 6ed5156..d7580ff 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,3 +6,6 @@ handle_ufw: false localnetworks: - 192.168.1.0/24 - 192.168.2.0/24 +motion_bot_ntfy_server: 'http://ntfy.sh' # Empty to skip ntfy option +motion_bot_ntfy_username: motion_bot +motion_bot_ntfy_password: "{{ vault_motion_bot_ntfy_pass }}" diff --git a/files/process_motion_event.sh b/files/process_motion_event.sh index 5f43d49..92a21b3 100644 --- a/files/process_motion_event.sh +++ b/files/process_motion_event.sh @@ -174,6 +174,21 @@ do move_to_port="${1}" shift ;; + "--ntfy-server") + shift + ntfy_server="${1}" + shift + ;; + "--ntfy-user") + shift + ntfy_user="${1}" + shift + ;; + "--ntfy-password-file") + shift + ntfy_password_file="${1}" + shift + ;; *) ;; esac @@ -200,6 +215,12 @@ if [ "${mail_alert}" == "true" ]; then echo "${data}" | jq '.' | mail -s "Motion event '${event_type}' on host '${motion_host}' camera '${camera_name}'" "${email_destination}" fi +if [ -n "${ntfy_server}" ]; then + ntfy_password="$(cat "${ntfy_password_file}")" + ntfy_data="${data}, \"topic\": \"motion_detection\"" + curl -s "${ntfy_server}" -d "${ntfy_data}" +fi + message "Sending Home Assistant event ..." result=$(curl -s -X POST -H "Authorization: Bearer ${ha_token}" -H "Content-Type: application/json" "${ha_url}/api/events/motion_event" -d "${data}") return_code=$? diff --git a/tasks/configure.yml b/tasks/configure.yml index 0eead67..bac1b46 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -204,3 +204,12 @@ compress } create: true + + - name: Ensure motion_bot password file exists + copy: + path: motion_bot_ntfy_password_file + content: "{{ motion_bot_ntfy_password }}" + mode: 0600 + owner: motion + group: motion + when: motion_bot_ntfy_server != '' diff --git a/templates/motion_hass.conf.j2 b/templates/motion_hass.conf.j2 index f3900b7..2e0b612 100644 --- a/templates/motion_hass.conf.j2 +++ b/templates/motion_hass.conf.j2 @@ -1,5 +1,5 @@ hass_token='{{ vault_haos_api_calls_token }}' -hass_uri='http://192.168.1.248:8123' +hass_uri='{{ home_assistant_server_uri }}' motion_config='/etc/motion/motion.conf' # debug_level='DEBUG' -on_movie_end="/usr/local/bin/process_motion_event.sh --move-to /srv/expendable_data/motion 192.168.1.251:/srv/expendable_data/ --move-to-port 1122 --remove-picture --email-destination '{{ recipient }}' --home-assistant-url http://192.168.1.248:8123 --home-assistant-token '{{ vault_haos_api_calls_token }}' --signal-destination '+358401871182' -e 'on_movie_end' -t '%t' -w '%w' -J '%J' -i '%i' -C '%C' -o '%o' -c '%$' -v '%v' -D '%D' -h '%h' -K '%K' -L '%L' -f '%f' -Q '%Q' -F '%fps' -q '%q' -N '%N' -n '%n' -h '%host'" +on_movie_end="/usr/local/bin/process_motion_event.sh --ntfy-server '{{ motion_bot_ntfy_server }}' --ntfy-user '{{ motion_bot_ntfy_username }}' --ntfy-password-file '{{ motion_bot_ntfy_password_file }}' --move-to /srv/expendable_data/motion 192.168.1.251:/srv/expendable_data/ --move-to-port 1122 --remove-picture --email-destination '{{ recipient }}' --home-assistant-url http://192.168.1.248:8123 --home-assistant-token '{{ vault_haos_api_calls_token }}' --signal-destination '+358401871182' -e 'on_movie_end' -t '%t' -w '%w' -J '%J' -i '%i' -C '%C' -o '%o' -c '%$' -v '%v' -D '%D' -h '%h' -K '%K' -L '%L' -f '%f' -Q '%Q' -F '%fps' -q '%q' -N '%N' -n '%n' -h '%host'"