Converting the Contents of a Sensor Attribute to a Time Series Stats Sensor

Hi All

I very rarely post on here, I have been HA for about 5 years burt this really has stumped me. Hopefully someone has some advice.

Ive just moved to a tracker energy tariff (UK based) which posts daily prices for the current and following days use. This allows me to adjust my usage to target cheaper days. So far so good.

Ive been looking at ways to take a longer term view (2-4 days out) to see if I can further shift usage in advance of cheaper rates coming in.

One factor that affects unit rates on this tracker tariff is UK power grid carbon intensity (how much renewable mix vs gas). there is an integration for this data which gives me a sensor called: sensor.grid_co2_uk_local_co2_intensity_forecast_48h, it has no state but in attributes it contains a forecast of carbon intensity for the previous few and following 48 hours and is formatted as per the attached image.

My desired outcome:

I would like to parse this data; the time stamp, the forecast intensity value and create a time series sensor that I can use to visualise the current and forecast carbon intensity - in order to predict pricing.

Ive tried a number of things, including pulling each entry into its own sensor, but I’m just hitting a wall with my knowledge. what Im looking to achieve i something like the line chart on this website: https://carbonintensity.org.uk/ (about half way down the page).

Sorry that was long, but hopefully clear! Any advice would be much appreciated.

Have a look at the Apex chart card. I don’t think you need an intermediate step/sensor. You can parse data like that in a data generator to plot it.

Thanks. I have limited experience with more complete UI design but I will take a look.

as per @parautenbach the apex chart card looks like the way to do to plot this data, but its way above my experience level. I will do somme testing, but if anyone has any idea how I would plat the ‘from’ time stamp against the intensity value on an apex chart that would be appreciated!

Thanks

hi, is it possible to show future days on an x axis config? Ive got the data to show, but its only showing data points up to the current time, and nothing beyond.

hi all, ive fixed this issue now - all good.

Please post your final config.

type: custom:apexcharts-card
header:
  show: true
  title: Carbon Intensity Forecast
  show_states: false
series:
  - entity: sensor.grid_co2_uk_local_co2_intensity_forecast_48h
    name: Past Intensity
    type: line
    color: blue
    data_generator: >
      var now = new Date();

      return entity.attributes.forecast.filter(entry => new Date(entry.from) <=
      now).map(entry => {
        return {
          x: new Date(entry.from),
          y: entry.intensity
        };
      });
  - entity: sensor.grid_co2_uk_local_co2_intensity_forecast_48h
    name: Future Intensity
    type: line
    color: green
    data_generator: >
      var now = new Date();

      return entity.attributes.forecast.filter(entry => new Date(entry.from) >=
      now).map(entry => {
        return {
          x: new Date(entry.from),
          y: entry.intensity
        };
      });

graph_span: 50h
span:
  start: day
  offset: +10h
apex_config:
  stroke:
    curve: smooth
    dashArray:
      - 1
      - 1
  xaxis:
    labels:
      show: true
  yaxis:
    title:
      text: gCO2eq/kWh
  legend:
    show: false
  annotations:
    yaxis:
      - 'y': 100
        strokeDashArray: 0
        borderColor: '#00E396'
        label:
          borderColor: '#00E396'
          style:
            color: '#fff'
            background: '#00E396'
          text: Low
      - 'y': 150
        strokeDashArray: 0
        borderColor: '#FEB019'
        label:
          borderColor: '#FEB019'
          style:
            color: '#fff'
            background: '#FEB019'
          text: Moderate
      - 'y': 200
        strokeDashArray: 0
        borderColor: '#FF4560'
        label:
          borderColor: '#FF4560'
          style:
            color: '#fff'
            background: '#FF4560'
          text: High

2 Likes