Need help with tracking my washing machine status

For a start, your triggers are missing anything to trigger at. All those below values you commented out are important - there needs to be something here to trigger at.

Given that you’re attempting to map every single step of your washing machine’s processes, this is likely to be challenging. I’d highly recommend you look to simplify it, particularly as you’re really only after the goal of notifying when it completes. As a starting point, I’d recommend an automation that simply maps the transition from idle, to operational, to off. Then once you’ve got that working, that’s when you look to make it more complicated.

See if this thread helps you out at all.

Hello again,

Played around with this and did a little more digging. I finally have the status changing between me turning off the Wemo insight, and turning it on and having ~ 3 amps running idle. I’ll work on the rest of the logic next but that won’t be for a day or so (no more laundry to do, lol)

Here is the code for anyone else whom it may help. I’ll update when completed.

- alias: 'Washer Idle'
  trigger:
      platform: numeric_state
      entity_id: switch.wemo_insight
      value_template: '{{ state.attributes.current_power_w }}'
      above: 1
      below: 5
  condition:
    condition: state
    entity_id: 'switch.wemo_insight'
    state: 'on'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Idle
        
- alias: 'Washer Off'
  trigger:
      platform: state
      entity_id: 'switch.wemo_insight'
      state: 'off'
  condition:
    condition: state
    entity_id: 'switch.wemo_insight'
    state: 'off'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Power and Wemo Off
1 Like

You might have a look at my implementation. See: Action when laundry is done

Maybe a sensor would be a more feasible choice? What’s the point of using an input_select?
Here are 2 code example that might help you
Sensor.yaml:

  day_night:
    friendly_name: 'День и ночь'
    value_template: >-
        {%- if now().hour >= 20 and now().hour < 23 %}
            Evening
        {%- elif now().hour >= 23 and now().hour < 24 %}
            Nightfall
        {%  elif now().hour >= 0 and now().hour < 6 %}
            Night
        {%  elif now().hour >= 6 and now().hour < 8 %}
            Cockcrow
        {% else %}
            Day
        {%- endif %}

Example 2

  light_level:
    friendly_name: 'Освещенность'
    value_template: >-
        {%- if states('sensor.flower_zal_light_intensity') | int <= 100 %}
            Dark
        {%- elif states('sensor.flower_zal_light_intensity') | int > 100 and states('sensor.flower_zal_light_intensity') | int < 650 %}
            Low light
        {% else %}
            Bright
        {%- endif %}
1 Like

Here’s how I did it with Aeotec Smart Switches; see if this helps:

Hi

Thanks @rpitera and @fversteegen for the help. I now i’m late in posting this, but I only got around to fixing it recently.

First and foremost; an updated backstory:

I wanted to track the wash cycles of my washing machine using a Wemo Insight. The Wemo insight is a 15amp wifi switch that also has power/current monitoring capabilities. By monitoring the power usage of the washer, I could send a notification to select devices when the wash load was complete.

At first, I tried to solve this tracking the filling, drain, spin, rinse, cycle of the dryer based on the ‘power’ (in watts) of the washer, and creating input_booleans. This did not work too well, as sometimes my washers current would drop down for some time in between readings of the power, and cause false flags for the input_booleans.

after reading @fversteegen and @rpitera 's replies, I ended up with a mixture of their working examples and created this one. I will end up tweaking it over time, but for now it works.

sensors.yaml

- platform: template
  sensors:
    washer_status:
      friendly_name: 'Washer Status'
      value_template: '{{ states.input_select.washer_status.state }}'
      
- platform: template      
  sensors:
    washer_current_power:
      friendly_name: 'Washing Machine Power'
      value_template: '{{ states.switch.wemoinsight.attributes.current_power_w }}'
      unit_of_measurement: 'W'

- platform: statistics
  name: 'Washer Average Watts'
  entity_id: sensor.washer_current_power
  sampling_size: 6

The first one is just a simple text sensor to read out on my card in the HA GUI to show the washer status. Those are in my input_select.yaml file (see below).

The second sensor is a live display of the current being used by the washing machine. Having a sensor added allowed me to see and graph in HA the power cycle of a wash load.

The third sensor is a statistics sensor to track a running average of the washing machine. This eliminated the times when my washer would change power states mid cycle due. The running average took longer to change, and hence worked better.

input_select.yaml

washer_status:
  name: 'Washer Status:'
  options:
    - Idle
    - Cleaning
    - Power Off
  initial: Power Off
  icon: mdi:washing-machine

Pretty self explanatory.

automations.yaml

- id: 'washer_idle'
  alias: 'Washer Idle'
  trigger:
    - entity_id: binary_sensor.washerpower_current
      platform: state
      to: 'off'
      for:
        minutes: 2
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Idle
    - service: notify.motog
      data:
        message: Wash cycle complete; enjoy the clean clothes!
        title: Wash Cycle Complete
    - service: notify.ios_ar_iphone
      data:
        message: Wash cycle complete; enjoy the clean clothes!
        title: Wash Cycle Complete
    - service: tts.google_say
      entity_id: media_player.man_cave_chromecast
      data:
        message: "Wash cycle complete; enjoy the clean clothes!"
- id: 'washer_running'
  alias: 'Washer Running'
  trigger:
    - entity_id: sensor.washer_average_watts_mean
      platform: numeric_state
      above: 6
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Cleaning
- id: 'washer_off'
  alias: 'Washer and Wemo Off'
  trigger:
    - entity_id: switch.wemoinsight
      platform: state
      to: 'off'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Power Off
- id: 'washer_wemo_auto_off'
  alias: 'Power down Wemo after 1 hour of inactivity on washer'
  trigger:
    - entity_id: binary_sensor.washerpower
      platform: state
      to: 'off'
      for:
        hours: 1
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: switch.turn_off
      entity_id: switch.wemoinsight
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Power Off
- id: 'washer_failed'
  alias: 'Washer has failed, something is wrong'
  trigger:
    - entity_id: binary_sensor.washerpower_current
      platform: state
      to: 'off'
      for:
        minutes: 10
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
      - condition: state
        entity_id: input_select.washer_status
        state: 'Cleaning'
  action:
    - service: notify.motog
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed
    - service: notify.ios_ar_iphone
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed
    - service: notify.ios_dr_iphone
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed

The automations.yaml is where the fun happens. washer_idle is the big one where as soon as the power of the washer drops to a certain level for 2 minutes; HA will send out a notification that the wash cycle is complete!

Thanks again to all for the help!

3 Likes

Alright, so I’m a little obsessed now. I ended up adding a counter to the status thanks to this post and can now track how long each wash cycle takes. By tracking the “triggering” event of a dummy input_boolean, you can measure time of the wash cycle itself.

input_boolean.yaml

  washer_stopwatch:
    name: Stopwatch
    initial: off
    icon: mdi:timelapse

sensor.yaml

- platform: template
  sensors:
    washer_stopwatch:
      friendly_name: "Wash Cycle Time"
      value_template: >
        {% if is_state('input_boolean.washer_stopwatch', 'off') %}
          {{ relative_time(states.automation.washer_running.attributes.last_triggered) }}
        {% elif is_state('sensor.washer_stopwatch', 'unknown') %}
          0 seconds
        {% else %}
          {{ states('sensor.washer_stopwatch') }}
        {% endif %}

This is the actual part that makes the magic happen thanks to @tboyce1.

automations.yaml

- id: 'washer_idle'
  alias: 'Washer Idle'
  trigger:
    - entity_id: binary_sensor.washerpower_current
      platform: state
      to: 'off'
      for:
        minutes: 2
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Idle
    - service: notify.motog
      data:
        message: Wash cycle complete; enjoy the clean clothes!
        title: Wash Cycle Complete
    - service: notify.ios_ar_iphone
      data:
        message: Wash cycle complete; enjoy the clean clothes!
        title: Wash Cycle Complete
    - service: tts.google_say
      entity_id: media_player.man_cave_chromecast
      data:
        message: "Wash cycle complete; enjoy the clean clothes!"
    - service: input_boolean.turn_off
      entity_id: input_boolean.washer_stopwatch
- id: 'washer_running'
  alias: 'Washer Running'
  trigger:
    - entity_id: sensor.washer_average_watts_mean
      platform: numeric_state
      above: 6
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Cleaning
    - service: input_boolean.turn_on
      entity_id: input_boolean.washer_stopwatch
- id: 'washer_off'
  alias: 'Washer and Wemo Off'
  trigger:
    - entity_id: switch.wemoinsight
      platform: state
      to: 'off'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Power Off
- id: 'washer_wemo_auto_off'
  alias: 'Power down Wemo after 1 hour of inactivity on washer'
  trigger:
    - entity_id: binary_sensor.washerpower
      platform: state
      to: 'off'
      for:
        hours: 1
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
  action:
    - service: switch.turn_off
      entity_id: switch.wemoinsight
    - service: input_select.select_option
      data:
        entity_id: input_select.washer_status
        option: Power Off
- id: 'washer_failed'
  alias: 'Washer has failed, something is wrong'
  trigger:
    - entity_id: binary_sensor.washerpower_current
      platform: state
      to: 'off'
      for:
        minutes: 10
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'switch.wemoinsight'
        state: 'on'
      - condition: state
        entity_id: input_select.washer_status
        state: 'Cleaning'
  action:
    - service: notify.motog
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed
    - service: notify.ios_ar_iphone
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed
    - service: notify.ios_dr_iphone
      data:
        message: Wash cycle has failed; something is wrong!
        title: Wash Cycle Failed
    - service: tts.google_say
      entity_id: media_player.man_cave_chromecast
      data:
        message: "Wash cycle failed."

Only slightly modified. When the washer_stopwatch dummy input_boolean is turned on (during the cleaning status), it starts registering the time from then to when it was last off (when the washer is idle). This will then display the time in minutes. This is reset upon the next wash cycle all thanks to the automation.

wash_cycle

4 Likes

So I’ve decided to take the plunge and get this going. I “borrowed” the bulk of your configs and modified them a bit for my use. Took me a bit to get it up and running but am now running into these errors and can’t seem to figure out where I made a wrong turn. I’m hoping you and the others might be able to help me out.

Here are the errors I get:

2017-11-09 13:34:39 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.washer_stopwatch fails
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 204, in async_update_ha_state
yield from self.async_device_update()
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 307, in async_device_update
yield from self.async_update()
File “/usr/local/lib/python3.6/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/components/sensor/template.py”, line 155, in async_update
self._state = self._template.async_render()
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/helpers/template.py”, line 116, in async_render
return self._compiled.render(kwargs).strip()
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/jinja2/asyncsupport.py”, line 76, in render
return original_render(self, *args, **kwargs)
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 2, in top-level template code
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/jinja2/sandbox.py”, line 427, in call
return __context.call(__obj, *args, **kwargs)
File “/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/util/dt.py”, line 192, in get_age
delta = now() - date
TypeError: unsupported operand type(s) for -: ‘datetime.datetime’ and ‘str’
2017-11-09 13:34:39 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Washer Status: UndefinedError: ‘options’ is undefined
2017-11-09 13:34:40 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Washer Status: UndefinedError: ‘options’ is undefined
2017-11-09 13:34:40 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Washer Status: UndefinedError: ‘options’ is undefined
2017-11-09 13:34:40 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Washer Status: UndefinedError: ‘options’ is undefined

Both errors just repeat and repeat and repeat and repeat.

And here are the relevant portions of code:

washer_status_is.yaml (input_select):

name: 'Washer Status'
options:
  - Idle
  - Cleaning
  - Power Off
initial: Power Off
icon: mdi:washing-machine

washer_stopwatch_ib.yaml (input_boolean):

name: Washer Stopwatch
initial: off
icon: mdi:timelapse

washer_stopwatch,yaml (sensor template):

- platform: template
  sensors:
    washer_stopwatch:
      friendly_name: 'Wash Cycle Time'
      value_template: >
        {% if is_state('input_boolean.washer_stopwatch', 'off') %}
          {{ relative_time(states.automation.washer_running.attributes.last_triggered) }}
        {% elif is_state('sensor.washer_stopwatch', 'unknown') %}
          0 seconds
        {% else %}
          {{ state('sensor.washer_stopwatch') }}
        {% endif %}

washer_status.yaml (sensor template):

- platform: template
  sensors:
    washer_status:
      friendly_name: 'Washer Status'
      value_template: '{{ options.input_select.washer_status_is.options }}'

And finally, the 2 automations. (not using the power off or error ones just yet)

washer_idle.yaml :

alias: 'Washer Idle'
trigger:
  - entity_id: sensor.washer_current_consumption
    platform: numeric_state
    below: 1
    for:
      minutes: 3
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: 'switch.washing_machine'
      state: 'on'
action:
  - service: input_select.select_option
    data:
      entity_id: input_select.washer_status_is
      option: Idle
  - service: notify.HomeAssistantFE
    data:
      message: Wash cycle complete; put that shit in the dryer!
      title: Wash Cycle Complete
  - service: input_boolean.turn_off
    entity_id: input_boolean.washer_stopwatch_ib

washer_running.yaml:

alias: 'Washer Running'
trigger:
  - entity_id: sensor.washer_current_consumption
    platform: numeric_state
    above: 5
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: 'switch.washing_machine'
      state: 'on'
action:
  - service: input_select.select_option
    data:
      entity_id: input_select.washer_status_is
      option: Cleaning
  - service: input_boolean.turn_on
    entity_id: input_boolean.washer_stopwatch_ib

This is my first attempt at a more complex automation and templating so I expect that I’ve really screwed something up here; but for the life of me I just can’t figure it out. I’m hoping some fresh sets of eyes will be able to smack some sense into me.

Thanks!

This doesn’t look right to me, what are you trying to accomplish here?

Well there we have it. Fresh set of eyes does it.

Not sure where I got the ‘options.input_select.washer_status_is.options’ part (could have sworn I just copy pasted all of this but I guess I didn’t) but switching it to states.input_select.washer_status_is.state fixed it for me.

I followed your files and customized then for my solution.
But I cant get it to work…

Testing configuration at /home/homeassistant/.homeassistant
ERROR:homeassistant.config:Invalid config for [input_boolean]: expected a dictionary for dictionary value @ data['input_boolean']. Got [OrderedDict([('name', 'Washer Stopwatch'), ('initial', False), ('icon', 'mdi:timelapse')])]. (See ?, line ?). Please check the docs at https://home-assistant.io/components/input_boolean/
ERROR:homeassistant.setup:Setup failed for input_boolean: Invalid config.
ERROR:homeassistant.config:Invalid config for [input_select]: expected a dictionary for dictionary value @ data['input_select']. Got [OrderedDict([('washer_status', OrderedDict([('name', 'Washer Status'), ('options', ['Idle', 'Cleaning', 'Power Off']), ('initial', 'Power Off'), ('icon', 'mdi:washing-machine')]))])]. (See ?, line ?). Please check the docs at https://home-assistant.io/components/input_select/
ERROR:homeassistant.setup:Setup failed for input_select: Invalid config.
Failed config
  input_boolean: 
    - icon: mdi:timelapse
      initial: False
      name: Washer Stopwatch

  General Errors: 
    - Setup failed for input_boolean: Invalid config.
    - Setup failed for input_select: Invalid config.

  input_select: 
    - washer_status: [source /home/homeassistant/.homeassistant/input_selects/washer_status_is.yaml:1]
        icon: mdi:washing-machine
        initial: Power Off
        name: Washer Status
        options: [source /home/homeassistant/.homeassistant/input_selects/washer_status_is.yaml:3]
          - Idle
          - Cleaning
          - Power Off

Successful config (partial)
  input_boolean:
  input_select:

Any ideas?

You aren’t identifying each entity correctly, just input them as:

input_boolean:
  washer_stopwatch:
    name: Washer Stopwatch
    initial: off
    icon: mdi: timelapse

and:

input_select:
  washer_status:
    options:
      - Idle
      - Cleaning
      - Power Off
    initial: Power Off
    icon: mdi:washing-machine

Hi @derrick1985. It seems like automating the notification of washer/dryer status is a common desire! I found your post, and am attempting to adjust it for use with an Edimax switch which I bought a while back hoping to use the power monitoring aspect for this purpose, and am finally getting around to trying to implement it.

I’m stuck trying to understand what this binary_sensor is for. I can’t find any references as to how you defined it. Is it just part of your config that you just forgot to include in your post? Any reason you couldn’t just use a sensor.washer_average_watts_mean trigger with a below: 5 state?

Thanks for sharing your code!

Trying out a bit of this and the weird thing is I can take the code from the sensor and paste it into the template and it shows the time, but the sensor always says 0 seconds. I even cut out all the ifs just to see if it was dropping out to the static 0 for some odd reason. One minor piece driving me nuts.

  - platform: template
    sensors:
      dryer_doortime:
        friendly_name: "Door Open Time"
        value_template: >
          {{ relative_time(states.automation.dryer_door_stopwatch.attributes.last_triggered) }}

Never used relative_time before, but just tested on 0.70.1 and I get nothing returned, even in the template…
Bug?

Tried a couple different templates I found on the forums to do a simple stopwatch. Trying to do sensor showing a time of the current state of a sensor that is either “Drying” or “Door Open”, which turned out to be a mess of not working. Think I’ll just abandon and go with my original idea and just add it to my Nodered flow I have of dryer/washer notifications, have it push back a time in a loop every minute or something like that.

looks a bit complicated, but it works:
{{(as_timestamp(now()) - as_timestamp(states.sensor.upstairs_temperature.last_updated | default(0))) | timestamp_custom("%d")|int-1}} Days {{(as_timestamp(now()) - as_timestamp(states.sensor.upstairs_temperature.last_updated | default(0))) | timestamp_custom("%H")|int-1}} Hours {{(as_timestamp(now()) - as_timestamp(states.sensor.upstairs_temperature.last_updated | default(0))) | timestamp_custom("%M")|int}} Minutes ago

Think I recall finding another post of yours with that template but it was showing like 30 days for some odd reason when I threw it in the test template deal on the config page. I’ll give it a go in the yaml though and see what happens. On the list for tonight unless my Aliexpress package of goodies gets delivered…

1 Like

Showing Unknown if I paste it into the sensor template config, but in the templates tester page it shows the 30 days thing. When check the actual trigger time it shows a few seconds ago.

  - platform: template
    sensors:
      dryer_doortime:
        friendly_name: "Door Open Time"
        value_template: >
          {{(as_timestamp(now()) - as_timestamp(states.automation.dryer_door_stopwatch.attributes.last_triggered | default(0))) | timestamp_custom("%d")|int-1}} Days {{(as_timestamp(now()) - as_timestamp(states.automation.dryer_door_stopwatch.attributes.last_triggered | default(0))) | timestamp_custom("%H")|int-1}} Hours {{(as_timestamp(now()) - as_timestamp(states.automation.dryer_door_stopwatch.attributes.last_triggered | default(0))) | timestamp_custom("%M")|int}} Minutes ago
1 Like