How to multiply tibber hourly prices sensor x hourly consumption?

I want to compare the tibber prices and costs using my current consumption with the prices from the nordpool integration adjusted for tibber.

I have such a sensor and I also have a counter with the hourly consumption based on Riemann Sum integral and hourly counter.

But how can I count the costs ?

Here is a try with trigger that has not worked. The time pattern did nothing.
I have an automation running at the end of every hour and saving the hourly consuption into the input_number.

That triggers the template sensor , but the sensor increases too fast and those counters based on the sensor will usually increase about 2 times of the hourly consumption x price .

template:

  - trigger:
    - platform: time_pattern
      hours: "*"
      minutes: "*"
      seconds: "42"
      # does not work at all #

    - platform: state
      entity_id:
        - input_number.verbrauch_gesamt_0_1_der_letzten_stunde
      
    sensor:
      - name: TiBBER KOSTEN ZÄHLER - 0
        unique_id: tibber_kosten_zahler_0
        unit_of_measurement: "€"
        icon: mdi:counter
        state_class: "measurement"
        state: >
            {{  float ( states ('input_number.verbrauch_gesamt_0_1_der_letzten_stunde') )
              * float ( states ('sensor.nordpool_kwh_ger_eur_4_10_0') )
              / 100 | round(2) }}

Any ideas how to count the costs ?

Here is a chart with hourly prices and hourly consumption figures created by the automation with the input_number.

best solution so far:

I use the input_consumption_last_hour figure which is being updated by an automation every **.55.55 hour to feed an input cost counting (increasing) sensor which is multiplying the current hours consuption after 55:55 minutes with current tibber price per kWh.

This increasing input number (acting like an endless cost counter) then will be used for daily, weekly, monthly and yearly cost counters (and its reset automations).

Might not look clean but works at least quite stable so far as long as you avoid a restart in the minute before the end of an hour.

Hey, this seems too comlicated.
I did a similar thing where I wanted to know how much CO2 our energy use produces.
So what I did with the CO2 sensor is to make a “CO2 Emission now” sensor, which is a template
“load power (Watt) * emission/Wh”. That equals “emission/h”.
Now I needed to get rid of the time. Mathematically an intergal (riemann sum) does that. So I put the emission/h sensor in there as a source and got total CO2.

You can do this similary:
You probably have a power sensor, so multiply that with the tibber cost sensor and put it in the riemann sum. As a backup make an utility meter, so you can calibrate that, when an error occures.

If you only have energy of the last hour (kWh) of your load, multiply that with tibber and put that as a source of an utility meter with delta values enabled.

not really cause it works already reliable.

I have an automations which runs every hour at **:59:55 and

reads the current input_number.energy_cost

and then adds onto its value the costs of the current hours by multiplying this
consumption of the current hour
x
current price

before it writes this whole amount into input_number.energy_cost
as the new state of the counter.

From that input_number.energy_cost I create a sensor which acts like a constantly increasing counter

Based on that counter I finally have created the automaticly resetting daily / weekly / monthly / yearly counters.

That works quite well and I do not need a riemann sum integral cause I have that consumption of the last hour from a counter which counts what I have been drawing from the grid in the last hour.

Well, then just do this