No, I don’t use Telegram, don’t want to add another piece of software…
Going through an external service doesn’t really appeal to me either…
So I made an MQTT message that sends me the name of the sensor or whatever that gets activated; I append a line to a CSV including the date and time.
For those who are interested, my bash code:
#/bin/bash
############################################
## Sending PC temperature to Gladys ##
############################################
### Variables to customize
# Connection to the MQTT broker
User="gladys"
Pass="MonMDP"
Host="Le_PC_avec_Gladys"
# Device topic address
Topic="gladys/master/device/mqtt:maison:Informations/feature/mqtt:maison:Informations:Texte/text"
CSVFile="/home/hizoka/SurveillanceActiviteGladys.csv"
### Variables to customize
function CommandCheck()
{
# Function that checks for the presence of required commands
# Parameter: Command name and package (optional) separated by :
# E.g.: mosquitto_pub:mosquitto-clients
# If no parameter is given
[[ -z ${1} ]] && return 1
# Limit variables to the function
local Command Package Parameter ReturnValue
ReturnValue=0
# Process all parameters
for Parameter in "${@}"
do
Command="${Parameter%%:*}"
Package="${Parameter##*:}"
# If the command does not exist
if ! which ${Command} &>/dev/null
then
# Return value set to 1 to display all echos before stopping
ReturnValue=1
echo -e "[${ROUGE}Erreur${RAZ}] Arrêt du script car la commande ${BLEUFONCE}${Command}${RAZ} est introuvable." 1>2
# If a package is given
[[ ${Package} ]] && echo -e "Pour ubuntu : ${FUCHSIA}sudo apt-get install ${Package}${RAZ}" 1>2
fi
done
return ${ReturnValue}
}
# Colors for output display
FUCHSIA="\\e[1;35m"
RAZ="\\e[m"
BLEUFONCE="\\e[1;34m"
ROUGE="\\e[1;31m"
ORANGE="\\e[1m\\e[38;5;202m"
# Check for required commands which, if missing, cause the script to stop
# Requires the mosquitto_sub command from the mosquitto-clients package
! CommandCheck "mosquitto_sub:mosquitto-clients" && exit 1
# Infinite loop required if the program is launched with @reboot in cron
# Otherwise you should add a sleep before calling the script
while true
do
# Loop continuously listening to the Gladys device topic
# Retrieve responses into the variable Value
while read Value
do
# To avoid logging duplicate consecutive lines
if [[ $(tail -n 1 "${CSVFile}") != "${Value};$(date +'%d/%m/%y');$(date +'%H:%M')" ]]
then
echo "${Value};$(date +'%d/%m/%y');$(date +'%H:%M')" >> "${CSVFile}"
fi
done <<(mosquitto_sub -h "${Host}" -u "${User}" -P "${Pass}" -t "${Topic}")
sleep 1
done