Last active
August 31, 2023 14:24
-
-
Save rwunsch/def14ab8511500efea4667568d4c6f8d to your computer and use it in GitHub Desktop.
Curl Shelly Cloud for values of one Shelly (here Shelly 3EM) - once per second - and add to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SHELLY_KEY=<shelly-key from https://home.shelly.cloud/index.html#/user_settings> | |
SHELLY_CLOUD_SERVER=<shelly-cloud-server from https://home.shelly.cloud/index.html#/user_settings eg. https://shelly-61-eu.shelly.cloud> | |
DEVICE_ID= <device-id from https://home.shelly.cloud> | |
CSV_OUTPUT_FILE=shelly_values.csv | |
curl -s -X POST $SHELLY_CLOUD/device/status -d "id=$DEVICE_ID&auth_key=$SHELLY_KEY" | jq -r '.data.device_status."em:0" | del(.["user_calibrated_phase"]) | [.]' | \ | |
jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' > file.csv | |
while true | |
do | |
curl -s -X POST $SHELLY_CLOUD/device/status -d "id=$DEVICE_ID&auth_key=$SHELLY_KEY" | jq -r '.data.device_status."em:0" | del(.["user_calibrated_phase"]) | [.]' | \ | |
jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $rows[] | @csv' >> file.csv | |
echo " $(date +'%d.%m.%Y') $(date +'%H:%M:%S.%3N') : row added" | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment