Is it possible to select tariff state based on sensor

Hello HA friends, i have a question.
My solar panel meter outputs kWh and because I use 2 tariffs peak and off-peak (tariff 1 and 2), I would really like to calculate how much the solar panels have generated at peak and how much at off-peak. I also have a sensor that shows see which rate is currently being used.

Solar panel sensor:

  • sensor.kwh_meter_energy_export

P1 meter tariif:

  • sensor.p1_meter_tarief (which results in 1 or 2)

Tariffs peak and off-peak:

  • Peak € 0,36075
  • Off-peak. € 0,32036

I have already tried to create a sensor with a utility meter, but unfortunately I can’t figure it out. Is there a solution using .yaml with the above data, something like if the P1 meter is rate 1 then use Peak € 0.36075 and P1 meter is rate 2 then use Off-peak. €0.32036.

Thank you in advance for your efforts to help further, it is much appreciated.

W.r.t. HA I don’t know (yet) but I did some experiments with Node-RED and influxDB and a sort of ‘cloning’ of my P1 cable so that I can see the raw telegram text every 10 seconds. There is a value in there (0001) or (0002) that is the tarif so based on that, I put a Eurocents value in a database every hour. That works live/adhoc from now on, but I want to do also historic calculations, but that is another thing.

So from theory it should work I guess, but I also don’t know how. You can maybe look into the DSMR orignal parser code to see if that tarif line in the P1 telegram is used/extracted or not.