I’m new to Home Assistant and I’m trying to create some sensors for the washing machine based on the power provided by a smart plug.
I’m trying to have two sensors.
One for the washer with on/off statuses if the power > 0 and only if the status didn’t changed for 45 seconds.
Then the second sensor to have multiple statuses. Running (when the main sensor is on), finished for 30 seconds since the main sensor switched to off and none if the main switch is off and the 30 seconds passed.
Now I have two problems and don’t know how to resolve them.
I want that the delay (45 seconds) of the main sensor to apply only if power goes to 0 (just a nice to have)
When the main sensor is unavailable and then change to off the Job State sensor will change the state to finished. I don’t know how to check if the previous state was on together with the last_change
I like to solve such problems following the classic state machine approach. There are more compact solutions to this, but this one serves it’s purpose well, is super clean, and easily extendable.
Yes I know that the use of input_select is a bit unclean. I would do it differently today.
input_select:
waschmaschine_opstate:
name: Waschmaschine OpState
icon: mdi:washing-machine
options:
- "Off"
- "Standby"
- "Active"
- "Finished"
initial: "Off"
################################################################################
## Stephan Waschmaschine AEG
## 0.06 W = Off
## 4.3..6.3 W = Standby
## Bis 2000 W = Active
automation:
- id: "1609362853001"
alias: Regel Waschmaschine verbraucht ganz wenig (Off)
trigger:
- platform: numeric_state
entity_id: sensor.waschmaschine_schaltmessmodul_power
below: 0.1
for: "00:03:00"
condition:
condition: not
conditions:
- condition: state
entity_id: input_select.waschmaschine_opstate
state: "Off"
action:
- service: input_select.select_option
data:
entity_id: input_select.waschmaschine_opstate
option: "Off"
- id: "1609362853002"
alias: Regel Waschmaschine verbraucht 4.3W (Standby)
trigger:
- platform: numeric_state
entity_id: sensor.waschmaschine_schaltmessmodul_power
above: 4.0
below: 7.0
for: "00:01:00"
condition:
condition: state
entity_id: input_select.waschmaschine_opstate
state: "Off"
action:
- service: input_select.select_option
data:
entity_id: input_select.waschmaschine_opstate
option: "Standby"
- id: "1609362853003"
alias: Regel Waschmaschine verbraucht 4.3W (Finished)
trigger:
- platform: numeric_state
entity_id: sensor.waschmaschine_schaltmessmodul_power
above: 4.0
below: 7.0
for: "00:01:00"
condition:
condition: state
entity_id: input_select.waschmaschine_opstate
state: "Active"
action:
- service: input_select.select_option
data:
entity_id: input_select.waschmaschine_opstate
option: "Finished"
- id: "1609362853004"
alias: Regel Waschmaschine verbraucht >5W (Active)
trigger:
- platform: numeric_state
entity_id: sensor.waschmaschine_schaltmessmodul_power
above: 7.0
for: "00:01:00"
condition:
condition: not
conditions:
- condition: state
entity_id: input_select.waschmaschine_opstate
state: "Active"
action:
- service: input_select.select_option
data:
entity_id: input_select.waschmaschine_opstate
option: "Active"