which gets 0 or 1 depending on whether power is supplied to the heating element.
I know that the heating element consumes 0.150 kilowatts per hour. How can I calculate the consumed electricity and display this information?
The history stats can count how long a sensor has been on for a certain period (assuming the recorder has the information and not purged a part). It could calculate how long the sensor was on today, or yesterday. I guess that would be of use.
Problem is, if you are going to build an automation to sum up all uses of all days, things may get ugly if you run the automation to collect it too often or too little, or at the wrong time. So it would also be advisable to keep a timestamp up until when you alreay summed up as a total.
Maybe put in a feature request for an option to take a switch or a binary sensor and a wattage to create a power use sensor.
I do something similar with my oil burner run time. I have a binary sensor showing burner on/off, then history_stats to accumulate both today’s usage so far, and yesterday’s total: