27.12.2020, 12:45 
(This post was last modified: 27.12.2020, 12:50 by Erwin van der Zwart.)
		
	
	
		Hi,
Try this:
#mydata.data.variablePricesAndRenewables gives you the length of the subset variablePricesAndRenewables and you pick up the latest field of the sub set variablePricesAndRenewables
	
	
	
	
Try this:
Code:
local https = require('ssl.https')
local ltn12 = require('ltn12')
local json = require('json')
local cBody = '{"postcode": "3000"}'
local cReq = {}
result1 = https.request({
  url = 'https://api.amberelectric.com.au/prices/listprices',
  method = 'POST',
  headers = {
    ['content-length'] = #cBody,
    ['content-type'] = 'application/json'
  },
  source = ltn12.source.string(cBody),
  sink = ltn12.sink.table(cReq)
})
if (cReq) then 
  mydata =  json.pdecode(table.concat(cReq))
  log(mydata)
  totalfixedKWHPrice = mydata.data.staticPrices.E1.totalfixedKWHPrice
  log(totalfixedKWHPrice)
  lossFactor = mydata.data.staticPrices.E1.lossFactor
  log(lossFactor)
  -- Retrieve the current price - the latest period with type ACTUAL 
  wholesaleKWHPrice = mydata.data.variablePricesAndRenewables[#mydata.data.variablePricesAndRenewables].wholesaleKWHPrice
  log(wholesaleKWHPrice)
  currentPrice = totalfixedKWHPrice + lossFactor * wholesaleKWHPrice
  log(currentPrice)
end 
 

