Impossible History Stats

Take a look at the graph below, this history stat is impossible, the entity was on for 15 minutes in the x axis and the Y axis shows that it was on for 20 hours which it was not.

It also shows that it remained on until midnight which is also wrong.

This is not the only event of this type, it happens several times a month and throws my stats out such that they are not worth using ?

Any suggestions ?

I suggest you share the sensor config so we can check it.

Sure, thanks for helping:

- platform: history_stats
  name: PAC Boiler Week
  entity_id: sensor.pac_wiser_boiler
  state: 'On'
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=7) }}"
  end: "{{ now() }}"
    pac_wiser_boiler:
      value_template: >-
        {%- if states('sensor.wiser_hot_water') == "On" or states('sensor.wiser_heating') == "On"  -%}
        {{ "On" }}
        {%- else -%}
        {{ "Off" }}
        {% endif %}

The stats are to measure the time that the central heating boiler was firing