Binary sensor, history stats - display last n results and duration?

Hello,

Looking for guidance please; I have a binary sensor which goes ‘on’ when a circuit is above a certain power consumption and I would like to know how to correctly set up history_stats on the sensor so that the resultant graph resembles the hourly energy bar graph instead of the cumulative time as it does now.

Secondly is it possible to access the last n readings and duration for display on a lcd / tft? The latter I can do already for basic live states using rest api for arduino or using esphome but not historic data?

The template and graph are set up as:

  - platform: history_stats
    name: Heater History
    entity_id: binary_sensor.heater
    state: "on"
    type: time
    #start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
    duration:
      hours: 4

template:
  - binary_sensor:
      - name: "Heater"
        state: >
          {{ states('sensor.current_ct_02') | float(0) >= 3000}}
        unique_id: "0a7476cc-d6c1-40ba-8ae2-606518c3497s"

Thanks.