Efergy sensor implementation via scripting
Posted: Saturday 19 November 2016 17:25
It is already known that the efergy sensors have an API available which allows to access a lot of data. I implemented a simple script to collect the instantaneous power consumption and daily energy and feed it into a counter virtual device via JSON.
I have this script running on a Synology NAS every minute via crontab with no issues.
The only users modifications required should be adding your own token and modifying the idx of the virtual device accordingly to your own setup. The offset parameter in the second call to the API may also be modified according to your time zone.
I can see one potential improvement on adding a check in case the API is not available or returns an error. I will update the script when it's ready - however the API has been proving to be very reliable up to now.
Enjoy!
Code: Select all
p=$(curl -s 'http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=<token>' | jq -r .[].data)
e=$(curl -s 'http://www.energyhive.com/mobile_proxy/getEnergy?token=<token>&period=day&offset=-60' | jq -r .sum)
power=$(echo $p |cut -f2 -d":"|cut -f1 -d"}"| tr -d ' ')
energyToday=$(awk "BEGIN {print $e*1000}")
curl -s -i -H "Accept: application/json" "http://192.168.0.1:8084/json.htm?type=command¶m=udevice&idx=115&nvalue=0&svalue=$power;$energyToday" > /dev/null 2>&1
The only users modifications required should be adding your own token and modifying the idx of the virtual device accordingly to your own setup. The offset parameter in the second call to the API may also be modified according to your time zone.
I can see one potential improvement on adding a check in case the API is not available or returns an error. I will update the script when it's ready - however the API has been proving to be very reliable up to now.
Enjoy!