Personally, I would create a binary sensor for “Washer Running” and use that as your on/off trigger for your automation. You can build a delay into that. Makes for a handy sensor to display on your dashboard too.
template:
- binary_sensor:
- name: "Washer Running"
unique_id: washer_running
device_class: running
delay_on: 60 # set to longer than your power spikes
state: "{{ states('sensor.smart_switch_7_electric_consumption_w')|float(-1) > 3.1 }}"
Hey @jazzyisj this is pretty clever, actually, let the binary_sensor delay or “absorb” the 10-15 second spikes! like a hysteresis which is exactly what I’m looking for. I’ll give this shot.
Once I create the sensor with a 20 second delay:
template:
- binary_sensor:
- name: "Washer Running"
unique_id: washer_running
device_class: running
delay_on: 20 # set to longer than your power spikes
state: "{{ states('sensor.smart_switch_7_electric_consumption_w')|float(-1) > 3.1 }}"
Here’s the modified automation. If I did it correctly, it should not affect the existing timing system that was in place, and still work as normal.
alias: Washing Machine Status
description: For Washing Machine notification system
trigger:
- platform: state
entity_id: binary_sensor.washer_running
id: washing_started
to: on
from: off
- platform: state
entity_id: binary_sensor.washer_running
id: washing_ended
to: off
from: on
condition:
- condition: template
value_template: "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
action:
- if:
- condition: trigger
id: washing_started
alias: Washing Machine Started
then:
- service: zwave_js.set_config_parameter
data:
parameter: "21"
value: "0"
target:
device_id: 4d008806cd3f0815b7c45579c71444de
- service: zwave_js.set_config_parameter
data:
parameter: "23"
value: "120"
target:
device_id: 4d008806cd3f0815b7c45579c71444de
- service: input_datetime.set_datetime
data:
datetime: "{{ now() }}"
target:
entity_id: input_datetime.washing_machine_started
- service: input_datetime.set_datetime
data:
datetime: >-
{{ (now().timestamp() +
states('input_number.washing_machine_expected_runtime') | float(0))
| timestamp_local() }}
target:
entity_id: input_datetime.washing_machine_expected_time_to_stop
else:
- service: input_datetime.set_datetime
data:
datetime: "{{ now() }}"
target:
entity_id: input_datetime.washing_machine_stopped
- service: input_number.set_value
data:
value: >-
{{ (as_timestamp(states('input_datetime.washing_machine_stopped')) -
as_timestamp(states('input_datetime.washing_machine_started'))) |
float(0) }}
target:
entity_id: input_number.washing_machine_expected_runtime
- service: zwave_js.set_config_parameter
data:
parameter: "21"
value: "1"
target:
device_id: 4d008806cd3f0815b7c45579c71444de
- service: zwave_js.set_config_parameter
data:
parameter: "23"
value: "0"
target:
device_id: 4d008806cd3f0815b7c45579c71444de
- service: notify.mobile_app_sony_xperia_zx1
data:
message: Washing machine is done!
title: Washing Machine Status
- service: notify.mobile_app_iphone
data:
message: Washing machine is done!
title: Washing Machine Status
- service: tts.cloud_say
data:
entity_id: media_player.fire_tablet
message: The washing machine is done.
mode: single
You can still clean that up some. Combine the triggers. If you specify not_from: unknown, unavailable you don’t need the condition. You can use the binary sensor for your if: condition, then you don’t need a trigger id.
alias: Washing Machine Status
description: For Washing Machine notification system
trigger:
- platform: state
entity_id: binary_sensor.washer_running
to:
- "on"
- "off"
not_from:
- unknown
- unavailable
action:
- if:
- condition: state
entity_id: binary_sensor.washer_running
state: "on"
then:
- < do your stuff here for washer running on here>
else:
- < do your stuff here for washer running off here>
mode: single