Some background.
I have my washing machine connected to an energy monitoring plug. I’m using that to monitor the progress of a laundry cycle.
So far I have the following working:
- Hourly energy consumption of the washing machine
- Hourly cost to run the machine
- Current state of the washing machine based on instantaneous consumption (e.g. wash, spin, dry, etc)
- Notifications firing when the laundry cycle has finished
However, the last sensor I’d like to add is proving a little tricky. Basically I want to show how long the machine has been active for in its current cycle. I have a binary sensor that activates when energy consumption goes over a certain threshold (the machine starts its programme) and then turns off when it dips below (the machine is finished). I’d like to get the number of minutes that the sensor is ‘on’ since it was turned on, or otherwise zero.
My first thought was a history_stats
sensor, but unless I’m missing something it looks like this only returns hours, not minutes, which is not granular enough. Below is the config I was using:
- platform: history_stats
name: "Laundry duration"
entity_id: binary_sensor.washing_machine_in_use
state: on
type: time
start: '{{ states.binary_sensor.washing_machine_in_use.last_updated }}'
end: '{{ utcnow() }}'
This just seems to return zero all the time.
Is there any other way I can achieve what I want, perhaps with a template_sensor
instead? Kind of stumped on this one.