Last active
December 18, 2020 14:48
-
-
Save mschmitt/ae37f81a38e447e931a04d6e99c00ac8 to your computer and use it in GitHub Desktop.
Zählerstand der go-e Wallbox auslesen
This file contains hidden or 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 | |
url="http://go-echarger/status" | |
#url="https://api.go-e.co/api_status?token=abcdef0123" | |
if [[ "${url}" =~ api.go-e.co ]] | |
then | |
dataobject='.data' | |
else | |
dataobject='.' | |
fi | |
if ! json="$(curl -s "${url}" | jq "${dataobject}")" | |
then | |
printf "Unable to connect to: %s\n" "${url}" | |
fi | |
time="$(jq --raw-output .tme <<<"${json}")" | |
printf "Datum/Uhrzeit: %s.%s.%s %s:%s\n" \ | |
"${time:0:2}" "${time:2:2}" "${time:4:2}" "${time:6:2}" "${time:8:2}" | |
serial="$(jq --raw-output .sse <<<"${json}")" | |
printf "Seriennummer: %s\n\n" "${serial}" | |
key_card_id=('rca' 'rcr' 'rcd' 'rc4' 'rc5' 'rc6' 'rc7' 'rc8' 'rc9' 'rc1') | |
key_card_name=('rna' 'rnm' 'rne' 'rn4' 'rn5' 'rn6' 'rn7' 'rn8' 'rn9' 'rn1') | |
key_card_energy=('eca' 'ecr' 'ecd' 'ec4' 'ec5' 'ec6' 'ec7' 'ec8' 'ec9' 'ec1') | |
for (( card=0; card<=9; card++)) | |
do | |
# Is a card registered to this slot? | |
this_id="$(jq --raw-output ."${key_card_id["${card}"]}" <<<"${json}")" | |
if [[ -z "${this_id}" ]] | |
then | |
continue | |
fi | |
this_energy_raw="$(jq --raw-output ."${key_card_energy["${card}"]}" <<<"${json}")" | |
this_energy_kwh="$(( ${this_energy_raw} / 10 ))" | |
this_name="$(jq --raw-output ."${key_card_name["${card}"]}" <<<"${json}")" | |
printf "Zählerstand für Karte %s, ID %s (%s): %s kWh\n" "$(( ${card} + 1 ))" "${this_id}" "${this_name}" "${this_energy_kwh}" | |
done | |
energy_total_raw="$(jq --raw-output .eto <<<"${json}")" | |
energy_total_kwh="$(( ${energy_total_raw} / 10 ))" | |
printf "\nZählerstand insgesamt: %s kWh\n" "${energy_total_kwh}" |
Fixed. Was ein Murks mit Apple hey. 🤐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Knuts-MacBook-Pro:~ knut$ echo '{"foo": "0"}' | jq --raw-output .foo
0
Knuts-MacBook-Pro:~ knut$
Nun ist nur noch der Fehler in Zeile 39.
./go-e-zaehlerstand: line 39: "0" + 1 : syntax error: operand expected (error token is ""0" + 1 ")