Cost going down, while power use increases

Hello - I have the following issue with a smart plug. The power use in increasing, and the cost goes down from time to time. Primarily when I turn the smart switch off.


For the tariff, I have a time of use tariff. Peak, off-peak and shoulder rates. To make it more complex, the entire weekend is off-peak.

  - platform: template
    sensors:
      stereo_amp_cost:
        friendly_name: "Stereo Amp Cost"
        unit_of_measurement: "AUD"
        value_template: >
          {% set energy_consumed = states('sensor.stereo_energy_consumption') | float(0) %}
          {% set now = now() %}
          {% set is_weekend = now.weekday() in [5, 6] %}
          {% set peak_rate = 0.3783 %}
          {% set off_peak_rate = 0.2377 %}
          {% set shoulder_rate = 0.3556 %}
          
          {% if is_weekend %}
            {% set rate = off_peak_rate %}
          {% else %}
            {% if now.hour >= 22 or now.hour < 7 %}
              {% set rate = off_peak_rate %}
            {% elif 7 <= now.hour < 9 or 17 <= now.hour < 20 %}
              {% set rate = peak_rate %}
            {% elif 9 <= now.hour < 17 or 20 <= now.hour < 22 %}
              {% set rate = shoulder_rate %}
            {% else %}
              {% set rate = off_peak_rate %}
            {% endif %}
          {% endif %}
          
          {{ (energy_consumed * rate) | round(2) }}