Smappee water and gaz

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.

1 Like

After working on my solution, i made a crontab with that script and store the result into 2 files .txt.
From HA, I read the value from each file and I can get :

2 Likes

Going little forward, i made an automation rules that push up the controlled mechanical ventilation system if i use more than 5 littles of warm water in 5 minutes.

Hi,

What about your gas sensor data?
How do you get cold & hot water data?

same questions @doune

with 2 wires in my “smappee water and gaz module” and an access to smappee public API

We could consolidate all into one component. Let’s consolidate discussions here: Smappee custom component

do you have a smappee genius gateway device?

Hi, does anyone still have the updated script for water/gas ? Seems the API is free again

Also, how the sensor know if it’s cold or hot water? The meter doesn’t know??