Logic Machine Forum
Json API - Sonnen Battery - 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: Json API - Sonnen Battery (/showthread.php?tid=5527)



Json API - Sonnen Battery - epps - 22.07.2024

Hello there,

we want to integrate the "Sonnen" API to the Logicmachine.
We dont know how to implement this.
Can anyone help us please.
The settings we are see is this:

   

The documentation is attatched.

Thank you
Kind regards
Simon Epp


RE: Json API - Sonnen Battery - admin - 22.07.2024

Try this:
Code:
token = 'abcdef'
url = 'http://192.168.1.1/api/v2/latestdata'

resp, code, hdrs, stat = require('socket.http').request({
  url = url,
  method = 'GET',
  headers = {
    ['Auth-Token'] = token
  },
})

if code == 200 then
  data = require('json').pdecode(resp)

  log(data)

  consumption = data['Consumption_W']
  production = data['Production_W']
  state = data['ic_status']['statebms']

  log(consumption, production, state)
else
  log('request failed', resp, code)
end



RE: Json API - Sonnen Battery - epps - 22.07.2024

Thanks admin,

works great like always.

Smile