Read Plugwise Smile P1 meter data with HTTP requests
Example: Read Plugwise Smile P1 electricity/gas meter data with HTTP requests from Logic Machine 2
About Plugwise Smile P1
The Plugwise Smile P1 gives you realtime insight into your energy for both electricity and gas via smartphone or tablet.
Resident or Scheduled script
Execute the following program once in some specific time on Logic Machine 2 to read gas and electricity values and peak values.
- require('socket.http')
-
- socket.http.TIMEOUT = 5
- smiledata = socket.http.request('http://smile:hjzfhmdf@192.168.178.21/core/modules')
-
- if not smiledata then
- alert('Smile: cannot fetch data')
- end
-
- result = {}
-
- function starttag(parser, tag, args)
- if tag == 'measurement' then
- curkey = args.directionality
- if args.tariff_indicator then
- curkey = curkey .. '_' .. args.tariff_indicator
- end
-
- savevalue = true
- elseif tag:find('_meter') then
- curid = args.id
- result[ curid ] = { type = tag }
- end
- end
-
- function chardata(parser, text)
- if savevalue then
- result[ curid ][ curkey ] = tonumber(text)
- savevalue = false
- end
- end
-
- -- parse xml
- require('lxp').new({
- StartElement = starttag,
- CharacterData = chardata,
- }):parse(smiledata)
-
- -- log full result table
- log(result)
- -- log single consumption item
- log(result['ad2ea5e2498e4b658ee54ed149f5f0e8'].consumed)