Data extraction

Hi,

I’m unsure about unexpected state changes of some Zigbee sensors.

Is it possible to extract their state changes and the times they occurred?

I send myself messages in the chat, but the history is too short to get a clear overview.

What would be the best solution?

Thanks

Send yourself a Telegram message otherwise :slight_smile:

I’m following up on this topic.

It’s really not practical to send messages — isn’t there a better way to do this?
It’s really tedious to check what’s starting and what’s not…

So, I figured I could maybe send an MQTT message that I’d log to a CSV, but oh well…

Don’t you use Telegram? On Telegram, there’s no limit.

Otherwise make an HTTP call with the « HTTP Request » block, you can call a service like IFTTT that adds a row to a Google Sheet

There are plenty of possibilities :stuck_out_tongue:

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
3 Likes