TIBBER mit BASH Shell Script abrufen

Begonnen von wertz1234, 01 April 2023, 18:43:17

Vorheriges Thema - Nächstes Thema

wertz1234

Ausgelagertes Gedächtnis:




#!/bin/bash
# CURL zum Tibber API Abruf


CURL (){
QUERY_BODY="{ \"query\":\"{viewer {homes"
RESULT=$(curl \
-H "Authorization: Bearer ++++hier+++den+++bearer+++code+++einfuegen" \
-H "Content-Type: application/json" \
-X POST \
-d  "${QUERY_BODY}${QUERY}" \
https://api.tibber.com/v1-beta/gql)

}



c_subscription() {
QUERY="{currentSubscription {priceInfo {current {total energy tax startsAt }}}}}}\" }"
CURL

echo $RESULT |jq '.data.viewer.homes|.[].currentSubscription."priceInfo".current.total'
}

cd_subscription() {
QUERY="{currentSubscription {priceInfo { today { \
            total \
            energy \
            tax \
            startsAt \
          }}}}}}\" }"
CURL

echo $RESULT |jq '.data.viewer.homes|.[].currentSubscription."priceInfo"."today"|.[].total'

}

t_subscription() {
QUERY="{currentSubscription {priceInfo { tomorrow { \
            total \
            energy \
            tax \
            startsAt \
          }}}}}}\" }"
CURL

echo $RESULT |jq '.data.viewer.homes|.[].currentSubscription."priceInfo"."tomorrow"|.[].total'
}
consumption(){
QUERY="{consumption(resolution: HOURLY, last: 100) { \
        nodes {\
          from\
          to\
          cost\
          unitPrice\
          unitPriceVAT\
          consumption\
          consumptionUnit\
        }\
      }\
    }\
  }\
}\" }"
CURL

echo $RESULT |jq '.data.viewer.homes|.[].consumption.nodes|.[]|"from: ", .from, "Aktuelle Kosten: ", .cost'
}


adress(){
QUERY="{address { \
        address1\
        address2\
        address3\
        postalCode\
        city\
        country\
        latitude\
        longitude\
      }\
    }\
  }\
}\" }"
CURL
echo $RESULT |jq '.data.viewer.homes|.[]."address"|"Strasse: ",."address1", "PLZ: ", ."postalCode"'  


}


###### Program Start  ######
[ $# -eq 0 ] && usage
echo "$date $time Programm Aufruf $arg"  >> $logfile

while getopts csatd arg; do
  case $arg in
#-i: Last IP-Octet
#-s: Status
#-c: Connect
#-w: heat up
#-t: current temperature
#-r: automatic retract
#-h: Help
#-a: Target Head
#-l: list_files
#-p: pause program
s)
c_subscription
;;
d)
cd_subscription
;;
t)
t_subscription
;;
c)
consumption
;;
a)   
# silent
adress
;;

  esac
done
exit 0


ch.eick

RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick