Hi,
Today, it’s my turn to share my project :
- trying to get water consumption from my house (cold and hot water)
For that, i choose :
http://www.smappee.com/fr/moniteur-gaz-et-eau
I’ve already the “energy one” which has a local API so … pretty fun to get electricity consumption into HA and get warning in case of “too much consumption” according to my energy plan with my provider.
I asked to smappee for some credentials to access public API (doc available at : https://smappee.atlassian.net/wiki/display/DEVAPI/SmappeeDevAPI+Home)
and I wrote this little script in bash :
cat /home/homeassistant/.homeassistant/smappeeau.sh
#!/bin/bash
date -d "now" +%s%3N > timedudebut.txt
timedudebut=$(cat timedudebut.txt)
timedumoment=$(date -d "now" +%s%3N)
value=$((timedumoment+860000))
if [ $timedudebut -gt $value ]
then
hello=$(curl -silent --data 'grant_type=password&client_id=YOUR&client_secret=YOUR&username=YOUR&password=YOUR' https://app1pub.smappee.net/dev/v1/oauth2/token | grep -i access_token)
echo $hello > hello.json
jq -r '.access_token' hello.json > access_token.txt
jq -r '.refresh_token' hello.json > refresh_token.txt
access_token=$(cat access_token.txt)
refresh_token=$(cat refresh_token.txt)
fi
#echo '2e7254fc-c761-3e98-a32b-2c7ab9d159a5' > access_token.txt
starttime=$(date -d "0 day ago 00:00" +%s%3N)
endtime=$(date -d "now" +%s%3N)
access_token=$(cat access_token.txt)
echo "curl -silent -H 'Authorization: Bearer '${access_token}'' 'https://app1pub.smappee.net/dev/v1/servicelocation/17873/sensor/2/consumption?aggregation=3&from='${starttime}'&to='${endtime}'')"
var3=$(curl -silent -H 'Authorization: Bearer '${access_token}'' 'https://app1pub.smappee.net/dev/v1/servicelocation/17873/sensor/2/consumption?aggregation=3&from='${starttime}'&to='${endtime}'' | grep -v HTTP |grep -v Server |grep -v Server | grep -v Date | grep -v Content-Type | grep -v Transfer | grep -v Connection)
echo $var3 > result.json
value1=$(jq '.records[0].value1' result.json)
value2=$(jq '.records[0].value2' result.json)
echo $value1,$value2
It’s very dirty and it does not the job but i’m pretty close… indeed, if I run that script as HA user in an SSH command line, it work.
In the gui, I have :
showing that I have some access issue to get the access_token from the file where it is stored.