Bonjour,
Voici le script fourni par le fabricant et modifié pour fonctionner sur jeedom :
#!/bin/bash
# Requirements:
# This script uses jq for JSON parsing.
# apt install jq
# Description:
# This script fetches measurement data from the LabCom GraphQL API and displays it in a formatted table.
# The measurement records will be grouped by parameter and prints only the latest result each.
# Usage:
# ./labcom_api.sh
# --------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
#Langue
export LANG=C.UTF-8
# Ensure to replace YOUR-API-TOKEN with your actual API token before use
API_TOKEN="VOTRE TOKEN EN LAISSANT LES GUILLEMETS"
# Date range setup for fetching only required measurement records instead of all
AMOUNT_OF_DAYS=7
# Set a static timezone for date/time conversion
TIMEZONE="Europe/Berlin"
# --------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# API Configuration
API_ENDPOINT="https://backend.labcom.cloud/graphql"
now=$(date +%s)
date_filter=$((now - AMOUNT_OF_DAYS * 86400))
# Perform API call to fetch data
response=$(curl -s \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: $API_TOKEN" \
--data "{ \"query\": \"{ Accounts { forename surname Measurements (from: $date_filter) { scenario parameter unit value timestamp } } }\" }" \
$API_ENDPOINT)
convert_timestamp() {
TZ=$TIMEZONE date -d "@$1" +"%Y-%m-%d %H:%M"
}
# Define headers for the output table
#headers=$(echo -e "\033[1mSampling Point,Scenario,Parameter,Value,Unit,Timestamp\033[0m")
#headers=$(echo -e "\033[SScenario,Parameter,Value,Unit,Date\033[0m")
# Process the response and format it as a table
{
echo "$headers"
echo "$response" | jq -r '
.data.Accounts[]
| select(.Measurements | length > 0)
| {
name: (.forename + " " + .surname),
measurements: (.Measurements
| group_by(.parameter)
| map(max_by(.timestamp))
| sort_by(.timestamp))
}
| .name as $name
| .measurements[]
| "\($name),\(.scenario),\(.parameter),\(.value),\(.unit),\(.timestamp | @sh)"
' | while IFS=, read -r name scenario parameter value unit timestamp; do
formatted_timestamp=$(convert_timestamp "$timestamp")
echo -e "$scenario,$parameter,$(echo "scale=2; $value/1"| bc),$unit,$formatted_timestamp"
done
} | column -t -s,
#Fin du script