Logic Machine Forum
API Actual Power Efergy Engage Meter - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: API Actual Power Efergy Engage Meter (/showthread.php?tid=3145)



API Actual Power Efergy Engage Meter - Dirk79 - 04.02.2021

Hello everybody,
  
I have installed an Efergy Engage energy meter. By using the ‘getCurrentValuesSummary-url’ it returns:
 
[{"cid":"PWER","data":[{"1612478705000":2101}],"sid":"841163","units":"W","age":10}]
 
The 'sid' is the same every time. The number 2101 is the actual Power Consumption and changes. The big number in front of 2101 is also changing at every update (seems to be time related).
 
I would like to store the actual Power Consumption in a Virtual Object. Can you help me? Thank you very much!
 
This is my complete script:
 
json = require('json')
http = require('socket.http')
escape = require('socket.url').escape
require("user.telegram")
 
token = 'xxx'
url = 'https://private-anon-f58c0b5ab4-energyhiveapi.apiary-proxy.com/mobile_proxy/getCurrentValuesSummary?token=' .. escape(token)
 
CurrentValues = http.request(url)
--log(CurrentValues)
 
if CurrentValues then
 
  efergydatatable = json.pdecode(CurrentValues)
  --[[
  log (efergydatatable)
  
  cid= efergydatatable[1].cid
  log(cid)
  
  units= efergydatatable[1].units
  log(units)
  
  sid= efergydatatable[1].sid
  log(sid)
  
  age = efergydatatable[1].age
  log(age)
  
  data = efergydatatable[1].data
  log(data)
  ]]--
  
 
else
 
message("API Efergy Engage Hub met energiemeting Silverspas mislukt. Controleer de instellingen.")
 
end


RE: API Actual Power Efergy Engage Meter - admin - 05.02.2021

Try this:
Code:
if CurrentValues then
  efergydatatable = json.pdecode(CurrentValues)
  data = efergydatatable[1].data[1]
  key = next(data)
  consumption = data[ key ]
  grp.checkupdate('32/1/1', consumption)
end



RE: API Actual Power Efergy Engage Meter - Dirk79 - 05.02.2021

Wow! Solved. Thank you very much!!!