EFERGY API json, energy sensor Working

Moderator: leecollings

Post Reply
raxor
Posts: 8
Joined: Friday 17 April 2015 10:30
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

EFERGY API json, energy sensor Working

Post 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.
Last edited by raxor on Tuesday 24 August 2021 10:26, edited 3 times in total.
raxor
Posts: 8
Joined: Friday 17 April 2015 10:30
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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}]

Code: Select all

jq -r .[].data`
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&param=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
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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?
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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! :D

Thank you for making this "dummy" power meter smart!
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)
dpui7736
Posts: 11
Joined: Tuesday 26 July 2016 15:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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}]

Code: Select all

jq -r .[].data`
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&param=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
Snapperud
Posts: 1
Joined: Tuesday 27 September 2016 20:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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"
Ric68
Posts: 15
Joined: Wednesday 28 January 2015 17:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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
mungbeans
Posts: 1
Joined: Wednesday 01 August 2018 7:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: EFERGY API json, energy sensor. advice needed

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests