Create a sensor with 'old' values

Hi.

I am using the community integration Zonneplan ONE via HACS. This integration provides a numer of sensors that provide the power-tariff (ct per kWh) in the future (1 through 8 hours ahead).

My end-goal is to have a graph that shows the current power tariff and the tariff for the coming hours. (so I can set the delays on my washer, dishwasher, dryer, etc) including a time on the X-axis in accordance.)

I was looking to create a sensor that uses the data of the ‘in 8 hours’, but use the data of 8 hours ago (which would create a sensor that use ‘current and the coming 7 hours’). This seemed very simple as an idea, but typically enough I can’t seem to find a way to do this.
I also looked at doing it directly in a graph (also looked at APEX graph etc) but I was unable to find a way to get my desired results.

Does anyone have an idea?

Background:
I have the following sensors available:
Current tariff
Tariff in 1 hour
Tariff in 2 hours,

Tariff in 8 hours

As a temporary workaround I simply created a ‘glance’ that shows the figures of the sensors of above, but I would really like it to have it in a graph and not in a list.

1 Like

This post talks about how to insert data with historical timestamps using an automation.

This may also work using future timestamps.

If your goal is to create a graph, take a look on how @p1ranha solved this for a similar use case using Apex charts: Tibber sensor for future price (tomorrow) - #23 by p1ranha

Thanks :slight_smile:

I looked in to that, but that is outside of my capabilities.
I really don’t the get the data generator stuff.

My functional requirement is no longer there. The Zonneplan ONE integration no gives all the future data for up to one and a half day like below. And a second graph that currently has the data of tomorrow, using the offset of +24h. The only silly thing now is a few hours before midnight, the blue ‘Nu’ bar shows infront of the graph, but I can live with that.

graph

Code
type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 1d
header:
  title: Elektriciteitsprijs vandaag
  show: true
span:
  start: day
  offset: +0h
now:
  show: true
  label: Nu
all_series_config:
  show:
    extremas: true
  float_precision: 2
  fill_raw: 'null'
  extend_to: end
series:
  - entity: sensor.zonneplan_current_electricity_tariff
    name: Prijs
    opacity: 0.7
    data_generator: |
      return entity.attributes.forecast.map((start, index) => {
        return [new Date(start["datetime"]).getTime(), 
        entity.attributes.forecast[index]["price"]/10000000];
      });
    color_threshold:
      - value: -1
        color: lime
      - value: 0.1
        color: green
      - value: 0.2
        color: darkgreen
      - value: 0.35
        color: orange
      - value: 0.5
        color: red
      - value: 0.6
        color: purple
yaxis:
  - id: '1'
    min: '|-0.03|'
    max: '|+0.03|'
    align_to: 0.1
    decimals: 2
    apex_config:
      title:
        text: €/kWh
      tickAmount: 4
apex_config:
  xaxis:
    type: datetime
    tooltip:
      enabled: false
  chart:
    height: 320px
  legend:
    show: false
  stroke:
    show: true
    curve: stepline
    width: 5
  markers:
    size: 2