diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aca643..1b569cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). Changelog based on guidelines from [Keep a CHANGELOG](http://keepachangelog.com/). +## 2.0.0 +#### Changed: +- BREAKING: Moved lua scripts to lua folder, added shell folder. +#### Added: +- Shell scripts to send text and photos using Telegram bot. + ## 1.0.2 #### Fixed: - script_time_radar.lua had a bug, not sending messages. diff --git a/README.md b/README.md index 63b3982..23bcc30 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,22 @@ -# Domoticz Lua scripts -Collection of domoticz lua scripts, currently consisting of: +# Domoticz scripts +Collection of domoticz lua and shell scripts. +### Lua: - `script_time_radar.lua`: Radar detection and alerting on specified roads (Netherlands only) - `script_time_traffic.lua`: Traffic jam detection and alerting on specified routes +### Shell +Collection of domoticz lua scripts, currently consisting of: + +- `message.sh`: Send a text message using a Telegram bot +- `snapshot.sh`: Send a photo using a Telegram bot ## Installation: -Put the scripts you want inside your domoticz lua scripts folder: +Put the scripts you want inside your domoticz scripts folders: `domoticz/scripts/lua` +`domoticz/scripts/shell` -Keep the name of the script filenames the same, and they will be +Keep the name of the lua script filenames the same, and they will be triggered every minute (actual code execution every x minutes can be set inside every script). \ No newline at end of file diff --git a/script_time_radar.lua b/lua/script_time_radar.lua similarity index 100% rename from script_time_radar.lua rename to lua/script_time_radar.lua diff --git a/script_time_traffic.lua b/lua/script_time_traffic.lua similarity index 100% rename from script_time_traffic.lua rename to lua/script_time_traffic.lua diff --git a/shell/message.sh b/shell/message.sh new file mode 100755 index 0000000..0046b2b --- /dev/null +++ b/shell/message.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Shell script to send a text message using Telegram +# +# See https://core.telegram.org/bots#creating-a-new-bot how to create a +# Telegram bot. Fill in your token in the TOKEN variable below. +# +# Then create a group in which you add the bot, and anyone you want to +# receive the messages. Then fetch the chat_id of your group (can be tricky, +# Google "telegram get chat_id"). Then enter the CHAT_ID below. +# +# The script accepts 1 parameter, which should be the text to be sent. If your +# text contains spaces, wrap it in quotes: +# messages.sh "this is a test" +# +# (c) 2017 Johnny Mijnhout + +############## EDIT THESE SETTINGS TO YOUR PERSONAL VALUES ##################### + +TOKEN= +CHAT_ID= + +############################# END SETTINGS ##################################### + +TEXT=$1 +curl -s "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$CHAT_ID&text=$TEXT" > /dev/null & diff --git a/shell/snapshot.sh b/shell/snapshot.sh new file mode 100755 index 0000000..7416ebc --- /dev/null +++ b/shell/snapshot.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# Shell script to send photos using Telegram +# +# See https://core.telegram.org/bots#creating-a-new-bot how to create a +# Telegram bot. Fill in your token in the TOKEN variable below. +# +# Then create a group in which you add the bot, and anyone you want to +# receive the messages. Then fetch the chat_id of your group (can be tricky, +# Google "telegram get chat_id"). Then enter the CHAT_ID below. +# +# (c) 2017 Johnny Mijnhout + +############## EDIT THESE SETTINGS TO YOUR PERSONAL VALUES ##################### + +TOKEN= +CHAT_ID= + +############################# END SETTINGS ##################################### + +ROOT_DIR='/home/pi/Pictures/webcams' +DATE=`date +%Y%m%d` +TIME=`date +%H%M%S` +HOUR=`date +%H` +TEXT=$1 +START_HOUR=$2 +END_HOUR=$3 + +if [ ! -z "$START_HOUR" ] && [ ! -z "$END_HOUR" ]; then + if [ "$START_HOUR" -lt "$END_HOUR" ]; then + if [ "$HOUR" -lt "$START_HOUR" ] || [ "$HOUR" -gt "$END_HOUR" ]; then + exit 0 + fi + else + if [ "$HOUR" -lt "$START_HOUR" ] && [ "$HOUR" -gt "$END_HOUR" ]; then + exit 0 + fi + fi +fi + +if [ -z "$TEXT" ]; then + TEXT="Activiteit op $DATE om $TIME" +fi + +curl -s "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$CHAT_ID&text=$TEXT" > /dev/null & + +umask 000 +mkdir -p $ROOT_DIR/$DATE + +(avconv -rtsp_transport tcp -i 'rtsp://192.168.0.112:554/user=admin&password=&channel=1&stream=0.sdp?real_stream--rtp-caching=100' -f image2 -vframes 1 -pix_fmt yuvj420p $ROOT_DIR/$DATE/$TIME.garage.jpg > /dev/null 2>&1 && +curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" -F chat_id="$CHAT_ID" -F caption="$TEXT" -F photo="@$ROOT_DIR/$DATE/$TIME.garage.jpg" > /dev/null) & + +(avconv -rtsp_transport tcp -i 'rtsp://192.168.0.113:554/user=admin&password=&channel=1&stream=0.sdp?real_stream--rtp-caching=100' -f image2 -vframes 1 -pix_fmt yuvj420p $ROOT_DIR/$DATE/$TIME.voortuin.jpg > /dev/null 2>&1 && +curl -s -X POST "https://api.telegram.org/bot$TOKEN/sendPhoto" -F chat_id="$CHAT_ID" -F caption="$TEXT" -F photo="@$ROOT_DIR/$DATE/$TIME.voortuin.jpg" > /dev/null) & + +exit 0