How to get information about electricity consumption from a binary sensor?

I have a sensor from a floor heating thermostat

sensor:
   -platform:mqtt
     state_topic: "terneo_ax_160024/load"
     name: "Bathroom, floor under load"
     unique_id: "terneo_ax_160024cc"

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?

1 Like

To get it roughly, you might have a Time Pattern automation running every minute that would add 0.150 / 60 if the sensor is on?

EDIT: 0.150 kwH for a floor heating. Sure? I read about 100W per m² so you would have a very small bathroom…

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:

sensor:
  - platform: history_stats
    name: Burner on today
    entity_id: binary_sensor.boiler_burner
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

  - platform: history_stats
    name: Burner on yesterday
    entity_id: binary_sensor.boiler_burner
    state: 'on'
    type: time
    end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24

For longer term, I have an automation run daily to save yesterday’s value to a text file I can analyze off line.

Bathroom has about 8 square meters, but heating element is only 2 square meters. 150 watt total.

Do you have any example how can i use Time Pattern automation in my case?