Extract data from history component

Hi,

Is there a way to extract information from the history component and display this in a sensor? I am using home assistant to control my heating and am trying to work out a way of creating a sensor that displays how many minutes on that day there has been a demand heating (I.e how long MQTT switch set to on)

I have been toying with doing this in a separate python script and publishing a value by MQTT but was wondering if this could be done inside home assistant.