Save only maximum value per day

Platform information are irrelevant I think.
I am using OH3.

I only want to save and plot the maximum value for an item per day. How can I realise this?
To make it more plastical: I have the photovoltaic production and electric consumption of a plenticore inverter. The plotted values look like this:

Should I define a new item and setup a rule to get this value?

Yes. Two rules actually.

The first rule will trigger when the raw sensor Item changes and if the new value is grater than the state of the max Item’s state, update the max Item’s state with the current reading.

The second one, at midnight, will reset the max Item’s state to the current reading.

With your proposal the items cake can also change several times a day, but the ask was for the maximum value per day, what by definition of only one number per day and not multiple ones.

I would use persistence function maximumSince() and only run one rule at midnight

Given he’s plotting the value, it makes sense to plot the maximum up to that point in the day. Then you can see when during the day the max was reached and other similar trends.

If you only want the one value per day then yes, use persistence.

I do something similar for my PV system.

I have an item that represents the current power output of my solar PV: Solar_AC_Power. This gets stored into influxdb persistence on every change.

Then I have a rule in jruby:

rule 'Update max solar power' do
  changed Solar_AC_Power
  run do
    midnight = ZonedDateTime.now.truncatedTo(ChronoUnit::DAYS)
    midnight = midnight.minusDays(1) if TimeOfDay.now < '4am'
    max_since = Solar_AC_Power.maximum_since(midnight, :influxdb)
    Solar_AC_Power_Max.update max_since
    Solar_AC_Power_MaxTime.update max_since.timestamp
  end
end

You could do this without using persistence if you prefer, simply by comparing the current value vs the new value, e.g.

  midnight = ZonedDateTime.now.truncatedTo(ChronoUnit::DAYS)
  if Solar_AC_Power_MaxTime.is_before(midnight)
    # You could save the previous day's max value here if you want to
    Solar_AC_Power_Max.update 0 # Reset this for the new day
  end

  if Solar_AC_Power > Solar_AC_Power_Max
    Solar_AC_Power_Max.update Solar_AC_Power
    Solar_AC_Power_MaxTime.update Time.now # You could use ZoneDateTime.now if you prefer typing it
  end