Thanks so much for the ideas! I’m still learning about a few of the items you’ve used in your solution, but one thing I was wondering was why have you used a type ‘val’ instead of ‘var’ for PDlist and WSlist, given these will change at every update?
I’ve copied your code, but have made an error somewhere as the JSON transform for the PDresults and WSresults are returning NULL (I did enter the syntax you’ve used in an online evaluator, and it works with the input (rawjson) I have used, so I’ve done something else wrong).
import java.util.HashMap
import java.util.ArrayList
import java.util.Collections
val String filename = "power_price.rules"
rule "Get wholesale power price"
when
Time cron "0 0/1 * 1/1 * ? * " // or trigger every 30 minutes of every day starting on the 1st of each month (currently set to 1 minute for testing)
then
// Temporary JSON response for testing
var String response_json = '{"serviceResponseType":1,"data":{"currentNEMtime":"2021-02-11T20:33:42","postcode":"","networkProvider":"XXXXX","staticPrices":{"E1":{"dataAvailable":true,"networkDailyPrice":"18.04","basicMeterDailyPrice":"0","additionalSmartMeterDailyPrice":"15.3395","amberDailyPrice":"32.87671233","totalDailyPrice":"64.27779452","networkKWHPrice":"8.437","marketKWHPrice":"2.868","greenKWHPrice":"3.6388","carbonNeutralKWHPrice":"0.11","lossFactor":"1.05239169","offsetKWHPrice":"0.11","totalfixedKWHPrice":"11.41500","totalBlackPeakFixedKWHPrice":"NaN","totalBlackShoulderFixedKWHPrice":"NaN","totalBlackOffpeakFixedKWHPrice":"NaN"},"E2":{"dataAvailable":true,"networkDailyPrice":"0","basicMeterDailyPrice":"0","additionalSmartMeterDailyPrice":"0","amberDailyPrice":"0","totalDailyPrice":"0","networkKWHPrice":"1.903","marketKWHPrice":"2.868","greenKWHPrice":"3.6388","carbonNeutralKWHPrice":"0.11","lossFactor":"1.05239169","offsetKWHPrice":"0.11","totalfixedKWHPrice":"4.88100","totalBlackPeakFixedKWHPrice":"NaN","totalBlackShoulderFixedKWHPrice":"NaN","totalBlackOffpeakFixedKWHPrice":"NaN"},"B1":{"dataAvailable":true,"networkDailyPrice":"0","basicMeterDailyPrice":"0","additionalSmartMeterDailyPrice":"0","amberDailyPrice":"0","totalDailyPrice":"0","networkKWHPrice":"0","marketKWHPrice":"0","greenKWHPrice":"0","carbonNeutralKWHPrice":"0","lossFactor":"-1.05239169","offsetKWHPrice":"0","totalfixedKWHPrice":"0.00000","totalBlackPeakFixedKWHPrice":"NaN","totalBlackShoulderFixedKWHPrice":"NaN","totalBlackOffpeakFixedKWHPrice":"NaN"}},"variablePricesAndRenewables":[{"periodType":"ACTUAL","semiScheduledGeneration":"554.53","operationalDemand":"5972.27","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.2064","region":"VIC1","period":"2021-02-10T21:00:00","renewablesPercentage":"0.0928507920773843","periodSource":"30MIN","percentileRank":"0.8468468468468469"},{"periodType":"ACTUAL","semiScheduledGeneration":"615.21","operationalDemand":"5621.66","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.7301","region":"VIC1","period":"2021-02-10T21:30:00","renewablesPercentage":"0.10943564712202447","periodSource":"30MIN","percentileRank":"0.6486486486486487"},{"periodType":"ACTUAL","semiScheduledGeneration":"593.12","operationalDemand":"5333.73","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.4441","region":"VIC1","period":"2021-02-10T22:00:00","renewablesPercentage":"0.11120172937137801","periodSource":"30MIN","percentileRank":"0.5045045045045045"},{"periodType":"ACTUAL","semiScheduledGeneration":"598.37","operationalDemand":"5072.68","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.4309000000000003","region":"VIC1","period":"2021-02-10T22:30:00","renewablesPercentage":"0.11795934299029309","periodSource":"30MIN","percentileRank":"0.4954954954954955"},{"periodType":"ACTUAL","semiScheduledGeneration":"600.1","operationalDemand":"4917.48","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"2.9887000000000006","region":"VIC1","period":"2021-02-10T23:00:00","renewablesPercentage":"0.12203404996054891","periodSource":"30MIN","percentileRank":"0.27927927927927926"},{"periodType":"ACTUAL","semiScheduledGeneration":"579.83","operationalDemand":"5056.43","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.5408999999999997","region":"VIC1","period":"2021-02-10T23:30:00","renewablesPercentage":"0.1146718139082317","periodSource":"30MIN","percentileRank":"0.5495495495495496"},{"periodType":"ACTUAL","semiScheduledGeneration":"568.68","operationalDemand":"4972.53","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.5541000000000005","region":"VIC1","period":"2021-02-11T00:00:00","renewablesPercentage":"0.11436431756067836","periodSource":"30MIN","percentileRank":"0.5585585585585585"},{"periodType":"ACTUAL","semiScheduledGeneration":"522.71","operationalDemand":"4758.07","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.4639","region":"VIC1","period":"2021-02-11T00:30:00","renewablesPercentage":"0.10985756829975181","periodSource":"30MIN","percentileRank":"0.5225225225225225"},{"periodType":"ACTUAL","semiScheduledGeneration":"522.18","operationalDemand":"4570.57","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.3407000000000004","region":"VIC1","period":"2021-02-11T01:00:00","renewablesPercentage":"0.1142483322649035","periodSource":"30MIN","percentileRank":"0.45045045045045046"},{"periodType":"ACTUAL","semiScheduledGeneration":"583.77","operationalDemand":"4407.81","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.0382000000000007","region":"VIC1","period":"2021-02-11T01:30:00","renewablesPercentage":"0.13243991914352024","periodSource":"30MIN","percentileRank":"0.2972972972972973"},{"periodType":"ACTUAL","semiScheduledGeneration":"692.96","operationalDemand":"4252.45","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"2.3617","region":"VIC1","period":"2021-02-11T02:00:00","renewablesPercentage":"0.16295547272748653","periodSource":"30MIN","percentileRank":"0.24324324324324326"},{"periodType":"ACTUAL","semiScheduledGeneration":"819.17","operationalDemand":"4108.61","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.2122","region":"VIC1","period":"2021-02-11T02:30:00","renewablesPercentage":"0.19937886535835722","periodSource":"30MIN","percentileRank":"0.16216216216216217"},{"periodType":"ACTUAL","semiScheduledGeneration":"962.11","operationalDemand":"4068.99","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"0.9284000000000001","region":"VIC1","period":"2021-02-11T03:00:00","renewablesPercentage":"0.23644934000820844","periodSource":"30MIN","percentileRank":"0.09009009009009009"},{"periodType":"ACTUAL","semiScheduledGeneration":"1087.8","operationalDemand":"4003.01","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"0.8503000000000002","region":"VIC1","period":"2021-02-11T03:30:00","renewablesPercentage":"0.2717455115025943","periodSource":"30MIN","percentileRank":"0.06306306306306306"},{"periodType":"ACTUAL","semiScheduledGeneration":"1152.94","operationalDemand":"4054.94","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"-0.9833999999999999","region":"VIC1","period":"2021-02-11T04:00:00","renewablesPercentage":"0.2843297311427543","periodSource":"30MIN","percentileRank":"0"},{"periodType":"ACTUAL","semiScheduledGeneration":"1123.31","operationalDemand":"4163.17","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.2331","region":"VIC1","period":"2021-02-11T04:30:00","renewablesPercentage":"0.26982083364359366","periodSource":"30MIN","percentileRank":"0.17117117117117117"},{"periodType":"ACTUAL","semiScheduledGeneration":"1213.51","operationalDemand":"4311.58","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.0384","region":"VIC1","period":"2021-02-11T05:00:00","renewablesPercentage":"0.28145366663728844","periodSource":"30MIN","percentileRank":"0.14414414414414414"},{"periodType":"ACTUAL","semiScheduledGeneration":"1257.4","operationalDemand":"4621.36","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"2.5938","region":"VIC1","period":"2021-02-11T05:30:00","renewablesPercentage":"0.2720844080530407","periodSource":"30MIN","percentileRank":"0.26126126126126126"},{"periodType":"ACTUAL","semiScheduledGeneration":"1338.27","operationalDemand":"4849.08","rooftopSolar":"4.17","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"2.3683000000000005","region":"VIC1","period":"2021-02-11T06:00:00","renewablesPercentage":"0.2766063977746871","periodSource":"30MIN","percentileRank":"0.25225225225225223"},{"periodType":"ACTUAL","semiScheduledGeneration":"1439.58","operationalDemand":"5161.04","rooftopSolar":"62.23","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.168","region":"VIC1","period":"2021-02-11T06:30:00","renewablesPercentage":"0.2875229501825485","periodSource":"30MIN","percentileRank":"0.35135135135135137"},{"periodType":"ACTUAL","semiScheduledGeneration":"1581.59","operationalDemand":"5319.98","rooftopSolar":"181.004","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.3242000000000003","region":"VIC1","period":"2021-02-11T07:00:00","renewablesPercentage":"0.320414311330482","periodSource":"30MIN","percentileRank":"0.4144144144144144"},{"periodType":"ACTUAL","semiScheduledGeneration":"1649.09","operationalDemand":"5254.2","rooftopSolar":"288.601","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"2.992","region":"VIC1","period":"2021-02-11T07:30:00","renewablesPercentage":"0.3495869687546062","periodSource":"30MIN","percentileRank":"0.2882882882882883"},{"periodType":"ACTUAL","semiScheduledGeneration":"1765.18","operationalDemand":"5242.24","rooftopSolar":"512.975","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.8535000000000004","region":"VIC1","period":"2021-02-11T08:00:00","renewablesPercentage":"0.39584185821033624","periodSource":"30MIN","percentileRank":"0.2072072072072072"},{"periodType":"ACTUAL","semiScheduledGeneration":"1793.39","operationalDemand":"5290.37","rooftopSolar":"743.354","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"0.8646","region":"VIC1","period":"2021-02-11T08:30:00","renewablesPercentage":"0.4204275833631104","periodSource":"30MIN","percentileRank":"0.07207207207207207"},{"periodType":"ACTUAL","semiScheduledGeneration":"1849.65","operationalDemand":"5217.43","rooftopSolar":"942.579","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"0.9108","region":"VIC1","period":"2021-02-11T09:00:00","renewablesPercentage":"0.4532832663069162","periodSource":"30MIN","percentileRank":"0.08108108108108109"},{"periodType":"ACTUAL","semiScheduledGeneration":"1865.92","operationalDemand":"5248.98","rooftopSolar":"1113.67","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"0.23210000000000003","region":"VIC1","period":"2021-02-11T09:30:00","renewablesPercentage":"0.46829387126433175","periodSource":"30MIN","percentileRank":"0.036036036036036036"},{"periodType":"ACTUAL","semiScheduledGeneration":"1885.47","operationalDemand":"5343.02","rooftopSolar":"1239.545","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.6401","region":"VIC1","period":"2021-02-11T10:00:00","renewablesPercentage":"0.47474122929283646","periodSource":"30MIN","percentileRank":"0.1981981981981982"},{"periodType":"ACTUAL","semiScheduledGeneration":"1968.82","operationalDemand":"5461.42","rooftopSolar":"1307.89","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"-0.33660000000000007","region":"VIC1","period":"2021-02-11T10:30:00","renewablesPercentage":"0.48405376618887297","periodSource":"30MIN","percentileRank":"0.009009009009009009"},{"periodType":"ACTUAL","semiScheduledGeneration":"2061.17","operationalDemand":"5682.74","rooftopSolar":"1243.94","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.9844000000000002","region":"VIC1","period":"2021-02-11T11:00:00","renewablesPercentage":"0.47715644435718124","periodSource":"30MIN","percentileRank":"0.21621621621621623"},{"periodType":"ACTUAL","semiScheduledGeneration":"1993.97","operationalDemand":"5815.3","rooftopSolar":"1232.509","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"1.5532","region":"VIC1","period":"2021-02-11T11:30:00","renewablesPercentage":"0.4577988705426041","periodSource":"30MIN","percentileRank":"0.1891891891891892"},{"periodType":"ACTUAL","semiScheduledGeneration":"2077.11","operationalDemand":"6045.15","rooftopSolar":"1127.188","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.4539999999999997","region":"VIC1","period":"2021-02-11T12:00:00","renewablesPercentage":"0.44675780756567807","periodSource":"30MIN","percentileRank":"0.5135135135135135"},{"periodType":"ACTUAL","semiScheduledGeneration":"2010.35","operationalDemand":"6163.79","rooftopSolar":"1170.76","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.2119","region":"VIC1","period":"2021-02-11T12:30:00","renewablesPercentage":"0.43371576988363286","periodSource":"30MIN","percentileRank":"0.8558558558558559"},{"periodType":"ACTUAL","semiScheduledGeneration":"1912.94","operationalDemand":"6334","rooftopSolar":"1070.384","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.4990000000000006","region":"VIC1","period":"2021-02-11T13:00:00","renewablesPercentage":"0.40291319304887485","periodSource":"30MIN","percentileRank":"0.9099099099099099"},{"periodType":"ACTUAL","semiScheduledGeneration":"1875.1","operationalDemand":"6519.07","rooftopSolar":"1081.456","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.363700000000001","region":"VIC1","period":"2021-02-11T13:30:00","renewablesPercentage":"0.38899360386373255","periodSource":"30MIN","percentileRank":"0.8828828828828829"},{"periodType":"ACTUAL","semiScheduledGeneration":"1735.83","operationalDemand":"6641.06","rooftopSolar":"960.389","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.829","region":"VIC1","period":"2021-02-11T14:00:00","renewablesPercentage":"0.35469803191470467","periodSource":"30MIN","percentileRank":"0.918918918918919"},{"periodType":"ACTUAL","semiScheduledGeneration":"1645.13","operationalDemand":"6805.32","rooftopSolar":"866.817","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.1448","region":"VIC1","period":"2021-02-11T14:30:00","renewablesPercentage":"0.327411645542826","periodSource":"30MIN","percentileRank":"0.8198198198198198"},{"periodType":"ACTUAL","semiScheduledGeneration":"1636.65","operationalDemand":"7021.11","rooftopSolar":"718.162","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.2647","region":"VIC1","period":"2021-02-11T15:00:00","renewablesPercentage":"0.3042678949647977","periodSource":"30MIN","percentileRank":"0.8648648648648649"},{"periodType":"ACTUAL","semiScheduledGeneration":"1614.37","operationalDemand":"7092.7","rooftopSolar":"632.599","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.049100000000001","region":"VIC1","period":"2021-02-11T15:30:00","renewablesPercentage":"0.2908585156380355","periodSource":"30MIN","percentileRank":"0.7927927927927928"},{"periodType":"ACTUAL","semiScheduledGeneration":"1626.47","operationalDemand":"7133.5","rooftopSolar":"555.288","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.116200000000001","region":"VIC1","period":"2021-02-11T16:00:00","renewablesPercentage":"0.2837583764827434","periodSource":"30MIN","percentileRank":"0.8108108108108109"},{"periodType":"ACTUAL","semiScheduledGeneration":"1583","operationalDemand":"7064","rooftopSolar":"482.183","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.0920000000000005","region":"VIC1","period":"2021-02-11T16:30:00","renewablesPercentage":"0.27367253086759225","periodSource":"30MIN","percentileRank":"0.8018018018018018"},{"periodType":"ACTUAL","semiScheduledGeneration":"1493.37","operationalDemand":"7156.29","rooftopSolar":"371.711","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.2724","region":"VIC1","period":"2021-02-11T17:00:00","renewablesPercentage":"0.24775249099993477","periodSource":"30MIN","percentileRank":"0.8738738738738738"},{"periodType":"ACTUAL","semiScheduledGeneration":"1434.28","operationalDemand":"7067.67","rooftopSolar":"205.948","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8137000000000008","region":"VIC1","period":"2021-02-11T17:30:00","renewablesPercentage":"0.22550373143049304","periodSource":"30MIN","percentileRank":"0.6846846846846847"},{"periodType":"ACTUAL","semiScheduledGeneration":"1021.5","operationalDemand":"7072.96","rooftopSolar":"114.136","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"5.1381000000000006","region":"VIC1","period":"2021-02-11T18:00:00","renewablesPercentage":"0.15801041199394023","periodSource":"30MIN","percentileRank":"0.9279279279279279"},{"periodType":"ACTUAL","semiScheduledGeneration":"903.91","operationalDemand":"6927.94","rooftopSolar":"55.418","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"5.6155","region":"VIC1","period":"2021-02-11T18:30:00","renewablesPercentage":"0.1373734527142959","periodSource":"30MIN","percentileRank":"0.9459459459459459"},{"periodType":"ACTUAL","semiScheduledGeneration":"796.68","operationalDemand":"6846.46","rooftopSolar":"16.081","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"6.514200000000001","region":"VIC1","period":"2021-02-11T19:00:00","renewablesPercentage":"0.11843441081080608","periodSource":"30MIN","percentileRank":"0.990990990990991"},{"periodType":"ACTUAL","semiScheduledGeneration":"800.63","operationalDemand":"6834.05","rooftopSolar":"0.974","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"5.899300000000001","region":"VIC1","period":"2021-02-11T19:30:00","renewablesPercentage":"0.11727888592636983","periodSource":"30MIN","percentileRank":"0.972972972972973"},{"periodType":"ACTUAL","semiScheduledGeneration":"671.62","operationalDemand":"6731.66","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"5.8784","region":"VIC1","period":"2021-02-11T20:00:00","renewablesPercentage":"0.09977033896542606","periodSource":"30MIN","percentileRank":"0.963963963963964"},{"periodType":"ACTUAL","semiScheduledGeneration":"797.1","operationalDemand":"6484.81","rooftopSolar":"0","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.424200000000001","region":"VIC1","period":"2021-02-11T20:30:00","renewablesPercentage":"0.12291801918637554","periodSource":"30MIN","percentileRank":"0.8918918918918919"},{"period":"2021-02-11T21:00:00","periodType":"ACTUAL","periodSource":"5MIN","latestPeriod":"2021-02-11T20:35:00","region":"VIC1","rooftopSolar":"0","usage":"37871.52000","operationalDemand":"37871.52000","wholesaleKWHPrice":"5.35090","renewablesPercentage":"0.11660","percentileRank":"0.9369369369369369"},{"periodType":"FORECAST","semiScheduledGeneration":"774.883","operationalDemand":"5975.54","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-11T21:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"4.1970995","period":"2021-02-11T21:30:00","region":"VIC1","renewablesPercentage":"0.1296758117258022","periodSource":"30MIN","percentileRank":"0.8378378378378378"},{"periodType":"FORECAST","semiScheduledGeneration":"727.837","operationalDemand":"5690.44","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-11T22:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8456","period":"2021-02-11T22:00:00","region":"VIC1","renewablesPercentage":"0.12790522349765573","periodSource":"30MIN","percentileRank":"0.6936936936936937"},{"periodType":"FORECAST","semiScheduledGeneration":"727.672","operationalDemand":"5424.17","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-11T22:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8767487000000003","period":"2021-02-11T22:30:00","region":"VIC1","renewablesPercentage":"0.13415361244208793","periodSource":"30MIN","percentileRank":"0.7837837837837838"},{"periodType":"FORECAST","semiScheduledGeneration":"741.469","operationalDemand":"5250.52","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-11T23:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8456","period":"2021-02-11T23:00:00","region":"VIC1","renewablesPercentage":"0.14121820314940234","periodSource":"30MIN","percentileRank":"0.7027027027027027"},{"periodType":"FORECAST","semiScheduledGeneration":"745.414","operationalDemand":"5253.06","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-11T23:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8456","period":"2021-02-11T23:30:00","region":"VIC1","renewablesPercentage":"0.14190091108801345","periodSource":"30MIN","percentileRank":"0.7117117117117117"},{"periodType":"FORECAST","semiScheduledGeneration":"758.676","operationalDemand":"5157.49","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T00:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8456","period":"2021-02-12T00:00:00","region":"VIC1","renewablesPercentage":"0.14710178788519224","periodSource":"30MIN","percentileRank":"0.7207207207207207"},{"periodType":"FORECAST","semiScheduledGeneration":"777.302","operationalDemand":"4949.95","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T00:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.8456","period":"2021-02-12T00:30:00","region":"VIC1","renewablesPercentage":"0.15703229325548743","periodSource":"30MIN","percentileRank":"0.7297297297297297"},{"periodType":"FORECAST","semiScheduledGeneration":"789.727","operationalDemand":"4764.39","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T01:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.7587539000000008","period":"2021-02-12T01:00:00","region":"VIC1","renewablesPercentage":"0.1657561618591257","periodSource":"30MIN","percentileRank":"0.6576576576576577"},{"periodType":"FORECAST","semiScheduledGeneration":"756.021","operationalDemand":"4613.41","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T01:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.707256300000001","period":"2021-02-12T01:30:00","region":"VIC1","renewablesPercentage":"0.16387466104248266","periodSource":"30MIN","percentileRank":"0.6306306306306306"},{"periodType":"FORECAST","semiScheduledGeneration":"721.964","operationalDemand":"4482.2","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T02:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.6572954","period":"2021-02-12T02:00:00","region":"VIC1","renewablesPercentage":"0.1610735799384231","periodSource":"30MIN","percentileRank":"0.6216216216216216"},{"periodType":"FORECAST","semiScheduledGeneration":"684.434","operationalDemand":"4362.74","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T02:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.6158254","period":"2021-02-12T02:30:00","region":"VIC1","renewablesPercentage":"0.15688168444601328","periodSource":"30MIN","percentileRank":"0.6036036036036037"},{"periodType":"FORECAST","semiScheduledGeneration":"652.779","operationalDemand":"4317.93","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T03:00:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.5780855000000003","period":"2021-02-12T03:00:00","region":"VIC1","renewablesPercentage":"0.15117868978885715","periodSource":"30MIN","percentileRank":"0.5855855855855856"},{"periodType":"FORECAST","semiScheduledGeneration":"616.72","operationalDemand":"4305.99","rooftopSolar":"0","forecastedAt":"2021-02-11T20:30:00","forecastedAt+period":"2021-02-11T20:30:00+2021-02-12T03:30:00","createdAt":"2021-02-11T20:32:41","wholesaleKWHPrice":"3.5748130000000002","period":"2021-02-12T03:30:00","region":"VIC1","renewablesPercentage":"0.14322374181082634","periodSource":"30MIN","percentileRank":"0.5765765765765766"}]},"message":""}'
// Electricity price is calculated as follows:
// data.staticPrices.E1.totalfixedKWHPrice + data.staticPrices.E1.lossFactor * data.variablePricesAndRenewables.[period].wholesaleKWHPrice
var Number totalFixedKWHPrice = Float::parseFloat(transform("JSONPATH", "$.data.staticPrices.E1.totalfixedKWHPrice", response_json))
var Number lossFactor = Float::parseFloat(transform("JSONPATH", "$.data.staticPrices.E1.lossFactor", response_json))
var String rawjson = transform("JSONPATH", "$.data.variablePricesAndRenewables", response_json)
logInfo(filename, "totalFixedKWHPrice = " + String::format("%s", totalFixedKWHPrice))
logInfo(filename, "lossFactor = " + String::format("%s", lossFactor))
// OpenHAB forum proposed solution
var forecastWS="none found" // result placeholders
var forecastStamp = "-"
// get string results like ["2020-10-18T22:00:00", "2020-10-18T22:30:00", "2020-10-18T23:00:00"] - note these are not arrays
var String PDresults = transform("JSONPATH", "$.[?(@.periodType=='FORECAST')].period", rawjson)
logInfo(filename, "PDresults = " + String::format("%s", PDresults))
//--> This returns NULL
// get string results like ["4.5254957000000005", "4.8887993000000005", "4.3353760999999995"] - note these are not arrays
var String WSresults = transform("JSONPATH", "$.[?(@.periodType=='FORECAST')].wholesaleKWHPrice", rawjson)
logInfo(filename, "WSresults = " + String::format("%s", WSresults))
//--> This returns NULL
if (PDresults !== null && WSresults !== null) { // check found some
PDresults = PDresults.replace("[","").replace("]","")
val PDlist = PDresults.split(",")
WSresults = WSresults.replace("[","").replace("]","")
val WSlist = WSresults.split(",")
// now as Lists
val masterMap = new HashMap<String,String>()
for (var int i = 0; i < PDlist.size ; i++) {
masterMap.put(PDlist.get(i),WSlist.get(i)) // key-value
}
// all that to load hashmap, must be a more elegant way!
val sortedKeys=new ArrayList(masterMap.keySet())
Collections::sort(sortedKeys) //just sort keys as strings works okay
forecastWS = masterMap.get(sortedKeys.last) // use bottom key for oldest
forecastStamp = sortedKeys.last
}
logInfo(filename, "Oldest forecast - " + forecastWS + " on " + forecastStamp )
// power_price.postUpdate(calc_price)
end
Any thoughts on why I am getting NULL for PDresults and WSresults?
Thanks again for your help.