Processing JSON data feed from API - possible for in Webcore or too much? (Octopus Agile API)


#1

I recently worked on creating a piston based on the Octopus Agile Electricity API here - Parse "GET" JSON data into a variable?

Linked that and key terms above just in case anyone is research and can come across these threads.

In that original question I managed to achieve what I wanted at the time, which was to parse the data from the Octopus API and put it into a global variable which gave the current price of electricity.

On the back of that I was going to build pistons to turn things on/off at different thresholds.

The problem with this is that the prices vary quite a lot - one day you might not get any 30 minute slots under 4.5p, other days you might get minus prices that you really want to take advantage of.

When you have something like your hot water tank relying on it you want it to run for 6 hours a day, but you want it to run at the cheapest 6 hours of the day. Those hours don’t need to be consecutive it can turn on/off any anytime.

We spoke a little in the thread at how to do this but it would seem to be a good idea to get the new data for the next 24 hours and process it. The only guarantee is that 4pm to 7pm is the most expensive (very expensive) so it would be worth working out the average for the 24 hour period excluding these hours and perhaps turning it into percentages to get the average.

That way you could create a variable which is a percentage rather than a set price - and when the price is below certain percentages for that day you know you’d always be using the cheapest 20% of electricity available (be that 6p per kWh or -2p per kWh)

However i’m not sure if it’s possible to process that in webcore alone. The API when requesting the rates for the next 24 hours returns this

{
  "count": 57067,
  "next": "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-D/standard-unit-rates/?page=2",
  "previous": null,
  "results": [
    {
      "value_exc_vat": 6.42,
      "value_inc_vat": 6.741,
      "valid_from": "2020-04-03T21:30:00Z",
      "valid_to": "2020-04-03T22:00:00Z"
    },
    {
      "value_exc_vat": 7.48,
      "value_inc_vat": 7.854,
      "valid_from": "2020-04-03T21:00:00Z",
      "valid_to": "2020-04-03T21:30:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T20:30:00Z",
      "valid_to": "2020-04-03T21:00:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-03T20:00:00Z",
      "valid_to": "2020-04-03T20:30:00Z"
    },
    {
      "value_exc_vat": 8.16,
      "value_inc_vat": 8.568,
      "valid_from": "2020-04-03T19:30:00Z",
      "valid_to": "2020-04-03T20:00:00Z"
    },
    {
      "value_exc_vat": 9.68,
      "value_inc_vat": 10.164,
      "valid_from": "2020-04-03T19:00:00Z",
      "valid_to": "2020-04-03T19:30:00Z"
    },
    {
      "value_exc_vat": 9.68,
      "value_inc_vat": 10.164,
      "valid_from": "2020-04-03T18:30:00Z",
      "valid_to": "2020-04-03T19:00:00Z"
    },
    {
      "value_exc_vat": 9.33,
      "value_inc_vat": 9.7965,
      "valid_from": "2020-04-03T18:00:00Z",
      "valid_to": "2020-04-03T18:30:00Z"
    },
    {
      "value_exc_vat": 22.86,
      "value_inc_vat": 24.003,
      "valid_from": "2020-04-03T17:30:00Z",
      "valid_to": "2020-04-03T18:00:00Z"
    },
    {
      "value_exc_vat": 21.8,
      "value_inc_vat": 22.89,
      "valid_from": "2020-04-03T17:00:00Z",
      "valid_to": "2020-04-03T17:30:00Z"
    },
    {
      "value_exc_vat": 22.0,
      "value_inc_vat": 23.1,
      "valid_from": "2020-04-03T16:30:00Z",
      "valid_to": "2020-04-03T17:00:00Z"
    },
    {
      "value_exc_vat": 20.04,
      "value_inc_vat": 21.042,
      "valid_from": "2020-04-03T16:00:00Z",
      "valid_to": "2020-04-03T16:30:00Z"
    },
    {
      "value_exc_vat": 18.96,
      "value_inc_vat": 19.908,
      "valid_from": "2020-04-03T15:30:00Z",
      "valid_to": "2020-04-03T16:00:00Z"
    },
    {
      "value_exc_vat": 16.92,
      "value_inc_vat": 17.766,
      "valid_from": "2020-04-03T15:00:00Z",
      "valid_to": "2020-04-03T15:30:00Z"
    },
    {
      "value_exc_vat": 4.4,
      "value_inc_vat": 4.62,
      "valid_from": "2020-04-03T14:30:00Z",
      "valid_to": "2020-04-03T15:00:00Z"
    },
    {
      "value_exc_vat": 3.96,
      "value_inc_vat": 4.158,
      "valid_from": "2020-04-03T14:00:00Z",
      "valid_to": "2020-04-03T14:30:00Z"
    },
    {
      "value_exc_vat": 4.4,
      "value_inc_vat": 4.62,
      "valid_from": "2020-04-03T13:30:00Z",
      "valid_to": "2020-04-03T14:00:00Z"
    },
    {
      "value_exc_vat": 5.61,
      "value_inc_vat": 5.8905,
      "valid_from": "2020-04-03T13:00:00Z",
      "valid_to": "2020-04-03T13:30:00Z"
    },
    {
      "value_exc_vat": 5.94,
      "value_inc_vat": 6.237,
      "valid_from": "2020-04-03T12:30:00Z",
      "valid_to": "2020-04-03T13:00:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-03T12:00:00Z",
      "valid_to": "2020-04-03T12:30:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-03T11:30:00Z",
      "valid_to": "2020-04-03T12:00:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-03T11:00:00Z",
      "valid_to": "2020-04-03T11:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-03T10:30:00Z",
      "valid_to": "2020-04-03T11:00:00Z"
    },
    {
      "value_exc_vat": 6.18,
      "value_inc_vat": 6.489,
      "valid_from": "2020-04-03T10:00:00Z",
      "valid_to": "2020-04-03T10:30:00Z"
    },
    {
      "value_exc_vat": 5.1,
      "value_inc_vat": 5.355,
      "valid_from": "2020-04-03T09:30:00Z",
      "valid_to": "2020-04-03T10:00:00Z"
    },
    {
      "value_exc_vat": 6.18,
      "value_inc_vat": 6.489,
      "valid_from": "2020-04-03T09:00:00Z",
      "valid_to": "2020-04-03T09:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-03T08:30:00Z",
      "valid_to": "2020-04-03T09:00:00Z"
    },
    {
      "value_exc_vat": 6.95,
      "value_inc_vat": 7.2975,
      "valid_from": "2020-04-03T08:00:00Z",
      "valid_to": "2020-04-03T08:30:00Z"
    },
    {
      "value_exc_vat": 6.18,
      "value_inc_vat": 6.489,
      "valid_from": "2020-04-03T07:30:00Z",
      "valid_to": "2020-04-03T08:00:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T07:00:00Z",
      "valid_to": "2020-04-03T07:30:00Z"
    },
    {
      "value_exc_vat": 6.05,
      "value_inc_vat": 6.3525,
      "valid_from": "2020-04-03T06:30:00Z",
      "valid_to": "2020-04-03T07:00:00Z"
    },
    {
      "value_exc_vat": 4.84,
      "value_inc_vat": 5.082,
      "valid_from": "2020-04-03T06:00:00Z",
      "valid_to": "2020-04-03T06:30:00Z"
    },
    {
      "value_exc_vat": 6.49,
      "value_inc_vat": 6.8145,
      "valid_from": "2020-04-03T05:30:00Z",
      "valid_to": "2020-04-03T06:00:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T05:00:00Z",
      "valid_to": "2020-04-03T05:30:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-03T04:30:00Z",
      "valid_to": "2020-04-03T05:00:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T04:00:00Z",
      "valid_to": "2020-04-03T04:30:00Z"
    },
    {
      "value_exc_vat": 6.01,
      "value_inc_vat": 6.3105,
      "valid_from": "2020-04-03T03:30:00Z",
      "valid_to": "2020-04-03T04:00:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T03:00:00Z",
      "valid_to": "2020-04-03T03:30:00Z"
    },
    {
      "value_exc_vat": 6.58,
      "value_inc_vat": 6.909,
      "valid_from": "2020-04-03T02:30:00Z",
      "valid_to": "2020-04-03T03:00:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T02:00:00Z",
      "valid_to": "2020-04-03T02:30:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T01:30:00Z",
      "valid_to": "2020-04-03T02:00:00Z"
    },
    {
      "value_exc_vat": 6.78,
      "value_inc_vat": 7.119,
      "valid_from": "2020-04-03T01:00:00Z",
      "valid_to": "2020-04-03T01:30:00Z"
    },
    {
      "value_exc_vat": 6.6,
      "value_inc_vat": 6.93,
      "valid_from": "2020-04-03T00:30:00Z",
      "valid_to": "2020-04-03T01:00:00Z"
    },
    {
      "value_exc_vat": 6.4,
      "value_inc_vat": 6.72,
      "valid_from": "2020-04-03T00:00:00Z",
      "valid_to": "2020-04-03T00:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-02T23:30:00Z",
      "valid_to": "2020-04-03T00:00:00Z"
    },
    {
      "value_exc_vat": 6.18,
      "value_inc_vat": 6.489,
      "valid_from": "2020-04-02T23:00:00Z",
      "valid_to": "2020-04-02T23:30:00Z"
    },
    {
      "value_exc_vat": 6.31,
      "value_inc_vat": 6.6255,
      "valid_from": "2020-04-02T22:30:00Z",
      "valid_to": "2020-04-02T23:00:00Z"
    },
    {
      "value_exc_vat": 7.66,
      "value_inc_vat": 8.043,
      "valid_from": "2020-04-02T22:00:00Z",
      "valid_to": "2020-04-02T22:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-02T21:30:00Z",
      "valid_to": "2020-04-02T22:00:00Z"
    },
    {
      "value_exc_vat": 7.26,
      "value_inc_vat": 7.623,
      "valid_from": "2020-04-02T21:00:00Z",
      "valid_to": "2020-04-02T21:30:00Z"
    },
    {
      "value_exc_vat": 6.84,
      "value_inc_vat": 7.182,
      "valid_from": "2020-04-02T20:30:00Z",
      "valid_to": "2020-04-02T21:00:00Z"
    },
    {
      "value_exc_vat": 8.38,
      "value_inc_vat": 8.799,
      "valid_from": "2020-04-02T20:00:00Z",
      "valid_to": "2020-04-02T20:30:00Z"
    },
    {
      "value_exc_vat": 7.7,
      "value_inc_vat": 8.085,
      "valid_from": "2020-04-02T19:30:00Z",
      "valid_to": "2020-04-02T20:00:00Z"
    },
    {
      "value_exc_vat": 8.8,
      "value_inc_vat": 9.24,
      "valid_from": "2020-04-02T19:00:00Z",
      "valid_to": "2020-04-02T19:30:00Z"
    },
    {
      "value_exc_vat": 8.27,
      "value_inc_vat": 8.6835,
      "valid_from": "2020-04-02T18:30:00Z",
      "valid_to": "2020-04-02T19:00:00Z"
    },
    {
      "value_exc_vat": 7.92,
      "value_inc_vat": 8.316,
      "valid_from": "2020-04-02T18:00:00Z",
      "valid_to": "2020-04-02T18:30:00Z"
    },
    {
      "value_exc_vat": 20.48,
      "value_inc_vat": 21.504,
      "valid_from": "2020-04-02T17:30:00Z",
      "valid_to": "2020-04-02T18:00:00Z"
    },
    {
      "value_exc_vat": 20.26,
      "value_inc_vat": 21.273,
      "valid_from": "2020-04-02T17:00:00Z",
      "valid_to": "2020-04-02T17:30:00Z"
    },
    {
      "value_exc_vat": 20.06,
      "value_inc_vat": 21.063,
      "valid_from": "2020-04-02T16:30:00Z",
      "valid_to": "2020-04-02T17:00:00Z"
    },
    {
      "value_exc_vat": 19.6,
      "value_inc_vat": 20.58,
      "valid_from": "2020-04-02T16:00:00Z",
      "valid_to": "2020-04-02T16:30:00Z"
    },
    {
      "value_exc_vat": 18.5,
      "value_inc_vat": 19.425,
      "valid_from": "2020-04-02T15:30:00Z",
      "valid_to": "2020-04-02T16:00:00Z"
    },
    {
      "value_exc_vat": 17.51,
      "value_inc_vat": 18.3855,
      "valid_from": "2020-04-02T15:00:00Z",
      "valid_to": "2020-04-02T15:30:00Z"
    },
    {
      "value_exc_vat": 3.08,
      "value_inc_vat": 3.234,
      "valid_from": "2020-04-02T14:30:00Z",
      "valid_to": "2020-04-02T15:00:00Z"
    },
    {
      "value_exc_vat": 2.42,
      "value_inc_vat": 2.541,
      "valid_from": "2020-04-02T14:00:00Z",
      "valid_to": "2020-04-02T14:30:00Z"
    },
    {
      "value_exc_vat": 3.08,
      "value_inc_vat": 3.234,
      "valid_from": "2020-04-02T13:30:00Z",
      "valid_to": "2020-04-02T14:00:00Z"
    },
    {
      "value_exc_vat": 3.17,
      "value_inc_vat": 3.3285,
      "valid_from": "2020-04-02T13:00:00Z",
      "valid_to": "2020-04-02T13:30:00Z"
    },
    {
      "value_exc_vat": 3.96,
      "value_inc_vat": 4.158,
      "valid_from": "2020-04-02T12:30:00Z",
      "valid_to": "2020-04-02T13:00:00Z"
    },
    {
      "value_exc_vat": 5.15,
      "value_inc_vat": 5.4075,
      "valid_from": "2020-04-02T12:00:00Z",
      "valid_to": "2020-04-02T12:30:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T11:30:00Z",
      "valid_to": "2020-04-02T12:00:00Z"
    },
    {
      "value_exc_vat": 6.01,
      "value_inc_vat": 6.3105,
      "valid_from": "2020-04-02T11:00:00Z",
      "valid_to": "2020-04-02T11:30:00Z"
    },
    {
      "value_exc_vat": 5.17,
      "value_inc_vat": 5.4285,
      "valid_from": "2020-04-02T10:30:00Z",
      "valid_to": "2020-04-02T11:00:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T10:00:00Z",
      "valid_to": "2020-04-02T10:30:00Z"
    },
    {
      "value_exc_vat": 5.17,
      "value_inc_vat": 5.4285,
      "valid_from": "2020-04-02T09:30:00Z",
      "valid_to": "2020-04-02T10:00:00Z"
    },
    {
      "value_exc_vat": 5.94,
      "value_inc_vat": 6.237,
      "valid_from": "2020-04-02T09:00:00Z",
      "valid_to": "2020-04-02T09:30:00Z"
    },
    {
      "value_exc_vat": 6.27,
      "value_inc_vat": 6.5835,
      "valid_from": "2020-04-02T08:30:00Z",
      "valid_to": "2020-04-02T09:00:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-02T08:00:00Z",
      "valid_to": "2020-04-02T08:30:00Z"
    },
    {
      "value_exc_vat": 7.0,
      "value_inc_vat": 7.35,
      "valid_from": "2020-04-02T07:30:00Z",
      "valid_to": "2020-04-02T08:00:00Z"
    },
    {
      "value_exc_vat": 7.7,
      "value_inc_vat": 8.085,
      "valid_from": "2020-04-02T07:00:00Z",
      "valid_to": "2020-04-02T07:30:00Z"
    },
    {
      "value_exc_vat": 7.04,
      "value_inc_vat": 7.392,
      "valid_from": "2020-04-02T06:30:00Z",
      "valid_to": "2020-04-02T07:00:00Z"
    },
    {
      "value_exc_vat": 5.06,
      "value_inc_vat": 5.313,
      "valid_from": "2020-04-02T06:00:00Z",
      "valid_to": "2020-04-02T06:30:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T05:30:00Z",
      "valid_to": "2020-04-02T06:00:00Z"
    },
    {
      "value_exc_vat": 4.62,
      "value_inc_vat": 4.851,
      "valid_from": "2020-04-02T05:00:00Z",
      "valid_to": "2020-04-02T05:30:00Z"
    },
    {
      "value_exc_vat": 5.06,
      "value_inc_vat": 5.313,
      "valid_from": "2020-04-02T04:30:00Z",
      "valid_to": "2020-04-02T05:00:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T04:00:00Z",
      "valid_to": "2020-04-02T04:30:00Z"
    },
    {
      "value_exc_vat": 4.95,
      "value_inc_vat": 5.1975,
      "valid_from": "2020-04-02T03:30:00Z",
      "valid_to": "2020-04-02T04:00:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T03:00:00Z",
      "valid_to": "2020-04-02T03:30:00Z"
    },
    {
      "value_exc_vat": 4.07,
      "value_inc_vat": 4.2735,
      "valid_from": "2020-04-02T02:30:00Z",
      "valid_to": "2020-04-02T03:00:00Z"
    },
    {
      "value_exc_vat": 4.6,
      "value_inc_vat": 4.83,
      "valid_from": "2020-04-02T02:00:00Z",
      "valid_to": "2020-04-02T02:30:00Z"
    },
    {
      "value_exc_vat": 5.28,
      "value_inc_vat": 5.544,
      "valid_from": "2020-04-02T01:30:00Z",
      "valid_to": "2020-04-02T02:00:00Z"
    },
    {
      "value_exc_vat": 5.5,
      "value_inc_vat": 5.775,
      "valid_from": "2020-04-02T01:00:00Z",
      "valid_to": "2020-04-02T01:30:00Z"
    },
    {
      "value_exc_vat": 5.57,
      "value_inc_vat": 5.8485,
      "valid_from": "2020-04-02T00:30:00Z",
      "valid_to": "2020-04-02T01:00:00Z"
    },
    {
      "value_exc_vat": 4.64,
      "value_inc_vat": 4.872,
      "valid_from": "2020-04-02T00:00:00Z",
      "valid_to": "2020-04-02T00:30:00Z"
    },
    {
      "value_exc_vat": 4.62,
      "value_inc_vat": 4.851,
      "valid_from": "2020-04-01T23:30:00Z",
      "valid_to": "2020-04-02T00:00:00Z"
    },
    {
      "value_exc_vat": 4.95,
      "value_inc_vat": 5.1975,
      "valid_from": "2020-04-01T23:00:00Z",
      "valid_to": "2020-04-01T23:30:00Z"
    },
    {
      "value_exc_vat": 5.72,
      "value_inc_vat": 6.006,
      "valid_from": "2020-04-01T22:30:00Z",
      "valid_to": "2020-04-01T23:00:00Z"
    },
    {
      "value_exc_vat": 7.48,
      "value_inc_vat": 7.854,
      "valid_from": "2020-04-01T22:00:00Z",
      "valid_to": "2020-04-01T22:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-01T21:30:00Z",
      "valid_to": "2020-04-01T22:00:00Z"
    },
    {
      "value_exc_vat": 7.48,
      "value_inc_vat": 7.854,
      "valid_from": "2020-04-01T21:00:00Z",
      "valid_to": "2020-04-01T21:30:00Z"
    },
    {
      "value_exc_vat": 6.16,
      "value_inc_vat": 6.468,
      "valid_from": "2020-04-01T20:30:00Z",
      "valid_to": "2020-04-01T21:00:00Z"
    },
    {
      "value_exc_vat": 7.26,
      "value_inc_vat": 7.623,
      "valid_from": "2020-04-01T20:00:00Z",
      "valid_to": "2020-04-01T20:30:00Z"
    }
  ]
}

Does anyone know if something like the above would be possible at all, or is it worth using something externally (like a Python script or something maybe?) to process the data, or any other better ways to make us of it


#2

Quick example elaborating on the idea I mentioned earlier:

  • Grab the next 24 hours every day (shortly after the JSON updates)
  • Store them into variables. (or an array)
  • Use max() and min() to determine the highest and lowest points
  • Convert the max to 100, and the min to 0
  • Use the same formula to convert the other 22 dataPoints into percentages.

Once this is done, it should be easy to see what hours are a cheap price.
(compared to the other hours on that day)

A harder challenge will be your goal of only turning on during the cheapest 6 hours, since there will likely be multiple hours with identical percentages. But you cannot tackle that animal until you have the percentages worked out.


#3

Just thinking out loud here, but I think you will find the coding much easier if you think in terms of:

► cost less than X%… 6 times a day
instead of:
► cheapest 6 hours

In other words, say for instance you set a goal of your hot water heater can only be run when the price is in the cheapest 20%. It doesn’t need to do it’s first check until an hour before the first person typically wakes up… (let’s say 4am). When it triggers at 4, it checks to see the cost percentage. If it is expensive, nothing happens. If it is low priced, it can turn on the water heater, and set variable +1.

This can be done at key times throughout the day, or hourly between X & Y. Each successful run adds one to the variable. When it hits 6, it will not run again that day. Resets at midnight (or whenever the JSON updates)


#4

I definitely think you’re onto the right idea - the % thing got my thinking about it a lot.

I think it might be a benefit to me if I had a separate script running on my server to interpret the JSON data and spit out what I need.

I think if you ran the URL and it just gave you a percentage I could use that in Webcore more easily. Plus I could use it on other things like the car, or the space heaters etc.

I get your point about certain numbers having the same percentage. I think what the script would need to do is plot the numbers from cheapest to most expensive and on the off chance there are two numbers with the exact same amount just give one a higher percentage anyway so they are evenly spread.

Technically there are 42 useful results, if plotted evenly between 0 and 100% then technically 28.5% is always going to be 12 results, which would be the cheapest 12 results. So I could just always set the hot water to use results that return 30% or less and check every 30 minutes. It kills two birds with one stone…having the cheapest prices possible throughout the 24 hour period and it will be on for a maximum of 6 hours a day.

There is an IFTTT channel for the Octopus API too and one of the triggers is for when the new numbers are updated (anywhere between 4pm and 6pm) so I could use that to trigger my script running and to update.

Now, actually programming it and in what language is another thing all together.


#5

I’ve been giving this some thought, I think the way I’d approach it as follows.

I’m assuming you want to run the heater/car charger between certain times for a number of half hour slots (e.g 12 to run the water heater for 6 hours)

A piston would activate at the start time (e.g mid night or when you arrive home for the car) and would do the following

Read price points from Octopus API (42 results) into arrays within webcore
Loop through array no_intervals times (12 for water heater)
Identify cheapest unused time slot within time range and store result in array
Assuming array of cheapest times are in time order, from your start to end time
Loop through each slot in the array
Turn device on/off according to value
wait 30 mins

I think this should be doable in webcore, and given most of the complexity is before the device control loop, quite easy to test and see if the array of on times is correct.


#6

For what it’s worth, everything I have said above can be done here in webCoRE.


#7

How would you solve the issue of giving the same value a different percentage?


#8

I probably wouldn’t. (I like my numbers to be accurate) That is why I would try to set the “heater turn on percentage” to an ideal number, but use the +1 variable count to limit it to 6 hours a day. (or 12 half hours)

Also, since the water starts cooling the moment the heater is turned off, I would likely be strategic as to what times it tries to run. (IE: In my house, there’s no need to create piping hot water at 2AM)


#9

Although this is traditionally an economy 7 hot water tank so it usually turns on at midnight and off at 7am fully charged and provides water for the entire day. it’s not immediate - the over night element is at the bottom of the 240l tank, so if you’ve used all the hot water all day you’d generally want it to start at least 2am to get hot enough to provide enough for a shower in the morning - you could also though use the immersion switch which has an element further up the tank to provide more immediate hot water (though still slow)


#10

Consider yourself lucky… If I let my mind wander in the shower, I may end up with lukewarm temperatures by the end…


#11

Thinking a little more another way that might be slightly less complicated but along the same lines.

Retrieve the API data
Parse it into table/array
Sort by cheapest to most expensive
Instead of assigning it a percentage you could just request the amount of hours you need. So if instance if you need 6 hours, you know the first 12 results are cheapest 30 minute slots, so the actual financial result for the price of the 12 result that day will give you the amount you need to put into the script I create to turn on below that price and off above it.


#12

Thats similar to how I’d do it, however I think having multiple random on/off times may be awkward to programme.

I’d sort the array in to start to end time order, then parse it x times (where x= no half hour slots you need power/heat) on each parse set a bool flag to on for the cheapest unallocated as on period.
You;ll then have an array something like 0,0,1,1,1,0,0,1,0… where the first 0 is the first time period from your start time.
Then you just need a loop going through the entrys, switching on/off as indicated, waiting 30 mins before looping again.

Hope I’ve explained it clearly enough! It makes sense to me, let me know if you need any further clarification.


#13

Could someone post an example of how they’d do the sorting? I don’t really understand how you’d accomplish this bit.


#14

I would also be interested to see data sorted in webCoRE.
(There’s no mention of it on the Wiki, without some major convoluted coding)


#15

Anyone?


#16

I think you’ll have to code the sort. A bubble sort is probably simplest, psudo code below

n = countof(arr)
for(i = 0; i < n - 1; i++)
{
for(j = 0; j < n - i - 1; j++)
{
if(arr[j] > arr[j + 1])
{
// swap temp and arr[i]
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
}
}
}

Apologies I can’t get it to format with indents


#17

Just keep in mind that with 24 dataPoints, a bubble sort can take up to 300 passes… with each pass changing 3-5 variables… Meaning that a single query can easily be over a thousand calculations.

For what it’s worth, I am still leaning towards this method.