Page 1 of 1
EFERGY API json, energy sensor Working
Posted: Friday 17 April 2015 21:08
by raxor
Hi.
Efergy energy meter have a open API to retrieve info.
You only need create a new token for apps:
1- login with your efergy credentials in energyhive (efergy is a energyhive rebranded)
http://www.energyhive.com/settings/tokens
- Click on add token
And you can test json with this token here:
http://www.energyhive.com/content/about/develop
Code: Select all
your url with token are like this: http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=xxxxxxxxmytokenxxxxxxxxxx
this url returns exactly this:
[{"cid":"PWER","data":[{"1429296007000":609.385}],"sid":"591051","units":"kWm","age":8}]
My goal is parse "data" 609,385 watts to send every 1 minutes to Energy sensor in Domoticz.
PD: Finally it works, see next post
PD2: Edited in 2021, keeps working, efergy are reliable company. 6 years working without issues.
Re: EFERGY API json, energy sensor. advice needed
Posted: Monday 20 April 2015 0:27
by raxor
Finally i solved with jq
How-to install jq:
http://www.domoticz.com/wiki/Battery_le ... ing_system
input
[{"cid":"PWER","data":[{"1429473875000":285.085}],"sid":"591051","units":"kWm","age":12}]
returns
[{"1429473875000":285.085}]
Code: Select all
|cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
returns
285.085
finally mi Shellscript working perfectly (change token and domoticz IP and port)
Code: Select all
#!/bin/bash
energy=`curl 'http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=xxxxxxxxxxxxxxxxxxxxx' | jq -r .[].data`
resultado=`echo $energy |cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
curl -s -i -H "Accept: application/json" "http://192.168.1.xx:8080/json.htm?type=command¶m=udevice&idx=26&nvalue=0&svalue=$resultado;$resultado"
I put on crontab run every minute
Code: Select all
*/1 * * * * root /home/pi/domoticz/scripts/efergy.sh
Re: EFERGY API json, energy sensor. advice needed
Posted: Thursday 27 August 2015 21:06
by korniza
I m facing a problem with the script
I can get the results running on web browser, I installed jq 1.5 but i have the following running manual the script:
Code: Select all
/home/pi/domoticz/scripts/efergy.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 88 0 88 0 0 357 0 --:--:-- --:--:-- --:--:-- 606
HTTP/1.1 200 OK
Content-Length: 24
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
{
"status" : "ERR"
}
I m not a linux geek, so what I miss?
Re: EFERGY API json, energy sensor. advice needed
Posted: Thursday 27 August 2015 21:33
by korniza
I found the issue (sorry I m 3 hours user of the platform). I created a dummy hardware and after I created a virtual sensor as power meter. SO, I had tp get the id of new senson and replace it on
http://192.168.1.xx:8080/json.htm?type= ... &[b]idx=26[/b]&nvalue=0&svalue=$resultado;$resultado
so everything is working right now!
Thank you for making this "dummy" power meter smart!
Re: EFERGY API json, energy sensor. advice needed
Posted: Friday 19 August 2016 11:23
by dpui7736
raxor wrote:Finally i solved with jq
How-to install jq:
http://www.domoticz.com/wiki/Battery_le ... ing_system
input
[{"cid":"PWER","data":[{"1429473875000":285.085}],"sid":"591051","units":"kWm","age":12}]
returns
[{"1429473875000":285.085}]
Code: Select all
|cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
returns
285.085
finally mi Shellscript working perfectly (change token and domoticz IP and port)
Code: Select all
#!/bin/bash
energy=`curl 'http://www.energyhive.com/mobile_proxy/getCurrentValuesSummary?token=xxxxxxxxxxxxxxxxxxxxx' | jq -r .[].data`
resultado=`echo $energy |cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
curl -s -i -H "Accept: application/json" "http://192.168.1.xx:8080/json.htm?type=command¶m=udevice&idx=26&nvalue=0&svalue=$resultado;$resultado"
I put on crontab run every minute
Code: Select all
*/1 * * * * root /home/pi/domoticz/scripts/efergy.sh
Thank you for the script, it works well for me with some changes.
In Raspberry Pi 3:
I install jq with apg-get install jq
Add permissions to execute the script with sudo chmod +x /home/pi/domoticz/scripts/efergy.sh
Edit crontab with crontab -e and add line * * * * * /home/pi/domoticz/scripts/efergy.sh
Re: EFERGY API json, energy sensor. advice needed
Posted: Tuesday 27 September 2016 20:48
by Snapperud
Thanks for the info, very good.
I needed to pick two values, so I did this:
#!/bin/bash
energy=`curl '
http://www.energyhive.com/mobile_proxy/ ... xxxxxxxxxx' | jq -r .[].data`
tot=`echo $energy |cut -f2 -d":"|cut -f1 -d"}"| tr -d ' '`
car=`echo $energy |cut -f3 -d":"|cut -f1 -d"}"| tr -d ' '`
curl -s -i -H "Accept: application/json" "
http://192.168.xxx.xxx:8080/json.htm?ty ... =$tot;$tot"
curl -s -i -H "Accept: application/json" "
http://192.168.xxx.xxx:8080/json.htm?ty ... =$car;$car"
Re: EFERGY API json, energy sensor. advice needed
Posted: Sunday 23 October 2016 9:53
by Ric68
This was great, but I have a small problem which is probably very easy to solve, but since this is the first time I ever heard of jq, I thought that maybe someone with some more knowledge of jq could help making the script little more robust?
The problem that I have is that the meter is at the limit of the range, and I sometimes receive an error when reading from Efergy
The output is:
{"error":{"id":500,"desc":"Server Error","more":"Unable to get channel data for hid"}}
Instead of not updating the energy meter I get 0 as energy consumption
Re: EFERGY API json, energy sensor. advice needed
Posted: Wednesday 01 August 2018 7:17
by mungbeans
Hi
Big thanks for figuring this out and giving us the tutorial.
I just want to add in what I did to get a little more utility out of this bash script.
I created a bash script for crontab to run on bootup called autorun.sh
editing crontab (sudo crontab -e)
Code: Select all
@reboot sudo bash /home/pi/domoticz/scripts/autorun.sh
autorun.sh made in the scripts folder containing:
Code: Select all
#!/bin/bash
while true; do /home/pi/domoticz/scripts/efergy.sh
# Do something
sleep 6;
done
Looking at the API it has a 6 second refresh. I wanted to grab data every 6 seconds so I can log this in Domoticz.
This runs neatly in the background every 6 seconds. No ill effect on the system.