Many people have used power sensors to detect when a washing machine or dish washer has finished its cycle and needs to be unloaded. This typically monitors a standard current sensor using a smart plug, and triggers based on a change/fall in the current. I felt this was inelegant as it relied upon Home Assistant to continuously check the state of the current, when there is a perfectly good microcontroller which can do that for us.
The following ESPHome excerpt turns a typical smart plug into a sensor which will report on the state of a washing machine.
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO4
cf1_pin: GPIO5
model: BL0937
initial_mode: CURRENT
change_mode_every: 4294967295
update_interval: 2s
current:
name: "HLW8012 Current"
internal: true
on_value_range:
- below: 0.02
then:
- text_sensor.template.publish:
id: machine_state
state: "Off"
- above: 0.02
below: 0.1
then:
- text_sensor.template.publish:
id: machine_state
state: "Standby"
- above: 0.1
then:
- text_sensor.template.publish:
id: machine_state
state: "Running"
text_sensor:
- platform: template
name: "Washing Machine"
update_interval: 10s
icon: "mdi:washing-machine"
id: machine_state
It should be noted that this hides all of the regular power reporting sensors from Home Assistant. This suited my use-case, however it would be possible to make a hybrid sensor and expose this alongside the washing machine state. For my switch I also hid all of the regular smart controls, and configured the switch to always be on.