01.04.2020, 06:43
Use this websocket client library: https://forum.logicmachine.net/showthrea...23#pid7823
Create a user library named websocket and add this line after 'Connection: Upgrade', (line 289):
Example resident script, sleep time = 0, change token and homeId as needed:
Create a user library named websocket and add this line after 'Connection: Upgrade', (line 289):
Code:
'Sec-WebSocket-Protocol: graphql-ws',
Example resident script, sleep time = 0, change token and homeId as needed:
Code:
if not client then
ws = require('user.websocket')
json = require('json')
token = 'd1007ead2dc84a2b82f0de19451c5fb22112f7ae11d19bf2bedb224a003ff74a'
query = [[
subscription{
liveMeasurement(homeId:"c70dcbe5-4485-4821-933d-a8a86452737b"){
timestamp
power
accumulatedConsumption
accumulatedCost
currency
minPower
averagePower
maxPower
}
}
]]
url = 'wss://api.tibber.com/v1-beta/gql/subscriptions'
client, err = ws.client('sync', 10)
res, err = client:connect(url)
if res then
client:send(json.encode({
type = 'connection_init',
payload = 'token=' .. token,
}))
client:send(json.encode({
id = 1,
type = 'start',
payload = {
query = query
}
}))
else
log('connection failed: ' .. tostring(err))
client:close()
client = nil
end
else
data, _, _, opcode, err = client:receive()
if data then
data = json.pdecode(data)
if data then
log(data)
end
else
log('receive failed: ' .. tostring(err))
client:close()
client = nil
end
end