Octopus Agile - display tariff in graphs & tables, best import/export periods - all done using Node-RED and JSONata

I got it working, well I have cleared the errors. I had to ticket the Enable global context store. That was the only difference from my setup to your screenshot. Mine now looks like this.

Do I have to wait until 4.05pm to test. I can’t see how to trigger it manually.

Thanks again for the help.

The ‘enable global context store’ is optional. That just sets the websocket nodes to copy the entire HA state to a global context variable, which is useful if you know it is there.

The flow starts with an inject node. This can be set to trigger at NR start, and at regular intervals. I have set this to repeatedly trigger at 16:05 every day (just because I thought this a good time). However there is absolutely nothing stopping you from clicking the usual ‘button’ on the left and manually triggering the flow. The only time the manual button will not work is when you have made changes to a flow, and an ‘redeploy’ is required.

Enjoy.

I just removed the whole flow again for my own peace of mind. All I had to do was click on the blue icon, then the entity config, press update, done and deploy and it all worked. As you say, no need to tick the optional box.

My only issue now is, I have no prices. I have the sequence table.

This behaviour has been seen before by others but I have not yet worked out why.

You must have the tariff prices generated otherwise the sequence table would not appear. Check in the flow context for OctAgileTariff - array of 96 objects.

Your Octopus Agile Prices sensor has also fired - see the status for 10:30 (11:30 BST) at 11:50, so I assume all is OK there.

I think that HA does not like the size of the attributes (I am passing the entire array here which is quite large) and so it does not load them / show them in the developer > states list.

Others have reported that it all appears eventually, so check the flow context first.

I have made several changes to the flow to include DST and local time, however this just increases the size of the array and upsets HA even more, so I need to look at how to manage this better.

I do have 96 entries. I will leave it an see what happens.

Just a quick update. This is what I am seeing at the moment.

Ignore the Hourly Grid Consumption, that is a different card.

Yes, the Agile Sequences are fine, just the Agile Prices missing.

PedroKTFC fixed this previously by recreating the config nodes.

Alternatively, it may be down to my erroneous use of ‘State Class’ of measurement, which is no longer tolerated for strings. I suggest editing the Octopus Agile Sequences node, to be able to edit the sensor config node. In the config node, set the ‘state class’ to blank (top option) and try that.

That has fixed it. I assume you meant this part.

I changed Octopus Agile Sequences (I might not have press deploy in my haste), first that made no difference, I then changed Octopus Agile Prices and that worked. They are now both blank and I did press deploy.

Screenshot 2023-10-27 at 18.01.53

Thanks for sticking with me.

This all worked last January, albeit with my ‘incorrect’ setting. The Agile Sequence state is set to the count of sequences (the rest goes into the attributes) so can be regarded as a ‘measurement’. The Agile Prices state I set as the period timestamp, which is actually a string and thus not a measurement. In my early days I tended to set everything as ‘measurement’, now I know better.

As they say, it will be fixed in the next release…

Do you have a Buy Me a Coffee link. I would like to donate for this great project. It deserves support. How do we keep up on new releases? I will be spreading the word to my follows on Mastodon. There is a great Home Assistant community there.

Thank you kindly for your enthusiasm.

I am retired, and in all seriousness I only do this for fun and to learn new things. I have a solar PV system and I use HA / NR to be able to monitor and control it - been two years now and I am still working on the ‘project’. I don’t actually use Octopus Agile (looking at Flux as I think it is better).

Getting on top of Agile is essential for real-time control around dynamic pricing. There are many enthusiasts out there doing great work and building integrations for this, but I like the open nature of Node-RED, as well as the speed of prototyping. Anyone can, if they wish, pick up my flow and do what they like with it.

I have been fixing a couple of issues in this flow, adding DST time management, and a binary on/off best price sensor. The DST stuff is painfully difficult to test as clock change only happens twice a year, so I am planning on getting up at 01:45 tomorrow morning as I want to watch to see exactly when my Home Assistant Blue changes the internal time. Octopus Agile rates are all done as UTC, but there are potential issues if HA changes at an odd time in the middle of the night and my inverter is still waiting to be manually updated.

My current issue is that my flows are now too big to post here. Also, I have issues with the size of the array being moved in the attributes, and I would like to see if there is a way of distributing arrays over two or more sensors, then recombining in HA. I certainly need to try setting up with Node-RED projects and connecting to GitHub / Node-RED forum to see if I can improve the ‘release’ side of things, so don’t hold your breath!

Happy retirement :grinning:. What a great project to do in retirement. I obviously do use Agile along with my solar panels and battery. Luckily my inverter has an overnight charging option and will pick the best slots available for charging. I have manually choose how many slots it can use.

The bit I need to automate is force discharging before negative or zero slots. Saving Sessions will also be interesting when they start. If I can help in anyway or you need some information, please reach out.

I will be writing up my installation of your integration on my blog at some point. I am already behind on my blog updates :grinning:

I have been playing with the pricing table. I prefer the Markdown version as it drops slots and the table gets shorter as the day goes on.

This is what I am using at the moment

type: markdown
content: |-
  Time            Price
  {%- set results = state_attr('sensor.octopus_agile_prices', 'array') %}
  {%- for record in results %}
  {%- set ts = as_timestamp(record.from) %}
  {%- set ts_now = ((as_timestamp(now())/1800)|round(0,'floor')|int * 1800) %}
  {%- if ts >= ts_now %}
  {{ ts|timestamp_custom ('%H:%M', local=true)
  }}           {{
  record.import }}
  {%- endif %}
  {%- endfor %}
title: Octopus Agile Import Rates

I don’t understand how this one works

type: custom:flex-table-card
title: Octopus Agile times - IMPORT
entities:
  include: sensor.octopus_agile_sequence_table
columns:
  - data: import_array
    modify: x.sample
    name: Size
  - data: import_array
    modify: x.mode
    name: Mode
  - data: import_array
    modify: x.date
    name: Date
  - data: import_array
    modify: x.timefrom
    name: Start
  - data: import_array
    modify: x.timeupto
    name: Stop
  - data: import_array
    modify: x.duration
    name: Mins
  - data: import_array
    modify: x.average
    name: Cost (p)

I would love to find a way of formatting the table into bands. Red over X pence, yellow for Y pencce between X and Z, blue for Z pence which are the best slots. I will see what I can find. I think the issue might be, isn’t the pence value now a string and not a value?

OK so you want everything.

Flex Table, with the local time (not UTC - use with care), colour banding for price range, and only displaying tariff periods after now.

Flex table card settings:

type: custom:flex-table-card
strict: true
title: Octopus Agile Rates
entities:
  include: sensor.octopus_agile_prices
columns:
  - data: array
    modify: >-
      (new Date(x.from)).toLocaleString("en-GB", {day:"2-digit", month:"short",
      hour:"2-digit", minute:"2-digit", timeZoneName:"short"})
    name: Start Time (local)
  - data: array
    modify: |-
      let disp=(new Date(x.from) > new Date());
      if (disp) 'yes';
    name: TEST
    hidden: true
  - data: array
    modify: x.export
    name: Export
  - data: array
    modify: |-
      let val=x.import;
      let cr="f0a0a0";
      if   (val<15) cr="a0f0a0";
      else if (val<25) cr="f0f0a0";
      '<div style="background-color: #' + cr + ';">' + val + '</div>';
    name: Import

Looks like:

Thank you very much. I tweaked it slightly as I use dark mode and text was in white. I added a blue for below zero. I have no green and blue to test today :frowning:

type: custom:flex-table-card
strict: true
title: Octopus Agile Rates
entities:
  include: sensor.octopus_agile_prices
columns:
  - data: array
    modify: >-
      (new Date(x.from)).toLocaleString("en-GB", {day:"2-digit", month:"short",
      hour:"2-digit", minute:"2-digit", timeZoneName:"short"})
    name: Start Time (local)
  - data: array
    modify: |-
      let disp=(new Date(x.from) > new Date());
      if (disp) 'yes';
    name: TEST
    hidden: true
  - data: array
    modify: x.export
    name: Export
  - data: array
    modify: |-
      let val=x.import;
      let cr="FF3333";
      if   (val<15) cr="43AB00";
      if   (val<0) cr="0046AB";
      else if (val<25) cr="FF8000";
      '<div style="background-color: #' + cr + ';">' + val + '</div>';
    name: Import

I have updated to Node Red v15 and updated the companion app. No issues.

I finally have some rates below 10p. I have updated the table to look like this

type: custom:flex-table-card
strict: true
title: Octopus Agile Rates
entities:
  include: sensor.octopus_agile_prices
columns:
  - data: array
    modify: >-
      (new Date(x.from)).toLocaleString("en-GB", {day:"2-digit", month:"short",
      hour:"2-digit", minute:"2-digit", timeZoneName:"short"})
    name: Start Time (local)
  - data: array
    modify: |-
      let disp=(new Date(x.from) > new Date());
      if (disp) 'yes';
    name: TEST
    hidden: true
  - data: array
    modify: x.export
    name: Export
  - data: array
    modify: |-
      let val=x.import;
      let cr="FF3333";
      if (val < 0) {
        cr = "0046AB";
      } else if (val < 10) {
        cr = "00ab39";
      } else if (val < 20) {
        cr = "8300ab";
      } else if (val < 25) {
        cr = "FF8000";
      }
      '<div style="background-color: #' + cr + ';">' + val + '</div>';
    name: Import
view_layout:
  column: 3

Hi, apologies in advance - complete newbie to both HA and Node-Red.

I hope I’ve followed the instructions carefully. I did need to click “update” on the config nodes to get Deploy to work without error. I also removed the “measurement” state class. I’ve restarted HA and Node-Red several times. My challenge is “no connection” even after restarting flows. I did once see a green timestamp against the Half Hour flow, but it went again.

I think this is similar to the issue which needs delete config nodes? I’ve renamed them (not shown in screenshot), but I’m such a newbie I haven’t worked out how to recreate them if I delete them - sorry if that’s the truly basic level we are talking to resolve this.

EDIT: Noob got to the next level and worked out to click the “buttons” on the left against Manual and Half Hour! Timestamps are now green. However I still have no data in the entities… screenshot updated, this time with (empty) context flows

Well, firstly a big welcome to HA, and to Node-RED. Great that you have got this far - this stuff has quite a steep learning curve!

Well, the green status mark on the sensor entity nodes shows that the node has updated, and the status values are correct for today, so Node-RED and the flow is working!

Next step is to check HA and see what has been created.

Look in HA at Settings > Devices and Services > Integrations (first tab) > Node-RED Companion. Right hand box you should see “xx entities”. Click on this (it’s a link) and HA will list out the entities that have been created by Node-RED.

You should have Octopus Agile Sequence Table in the list, and clicking on it should show the history, and the attributes box below, so you can check the sensor state (which is the count of the sequences - 6 at the moment) and the attributes.

If not, then yes we have to check out the HA server. This is the configuration node (see the configuration tab in the RH debug window, look under ‘server’ for 'homeassistant)

The usual rules still apply - you should have the latest Node-RED addon (assuming you are using HA supervised) and the latest Node-RED companion integration, and a comparable set of Home Assistant WebSocket nodes in your Node-RED palette. WARNING - DO NOT update to the latest 0.62.2 if you are using Node-RED as an HA addon! The latest WebSocket node set is not compatible…

So, the Node-RED flow is OK, you can check to see if the HA entities have been created and updated. Then we will need to check the HA server.

Your screenshot shows the HA state being created by the HA server in global configs, so I assume it is working. These things can indeed be difficult to debug…

Thank you for the fast response on a Friday night!

I still have no data in the context flow, but I do now have data in the entities - maybe it was just walking away for 20 minutes? I swear I checked this before and it wasn’t there.

Somehow in my messing about, it’s created two sets of entities (how to remove the first ones?), but now that one of the sets has data, it was a breeze to update the apexcharts-card code to “…_2” sensor names and the chart is working!

Thanks for doing this, I think it has great potential for my use case to control Tuya-connected immersion heater initially (not time sensitive - like an unsophisticated battery) and heat pump if I can work out some sensible logic. Then batteries when I get some. Cheers!