Page 1 of 1

Efergy sensor implementation via scripting

Posted: Saturday 19 November 2016 17:25
by manutremo
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.

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&param=udevice&idx=115&nvalue=0&svalue=$power;$energyToday" > /dev/null 2>&1
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!

Re: Efergy sensor implementation via scripting

Posted: Saturday 19 November 2016 17:57
by Westcott
Hi Manutremo,

That looks really neat!
Which Efergy sensor are you using, or which ones support this method?

Re: Efergy sensor implementation via scripting

Posted: Sunday 20 November 2016 15:53
by manutremo
Hi Westcott,

I'm using an Efergy hub kit. I haven't used other models but as far as I know the API is model independent so the script should work with any model that sends its data to the internet.

I used the API description here http://napi.hbcontent.com/document/index.php.

Thanks,