Automation/script advice

Hi there, I’m trying to automate aspects of my washing machine in my shared house. I have a TP-Link HS110 socket on the washing machine so I can monitor power consumption and a Flic2 button on the machine for us to select whose washing it is going in.

What I want to happen is the person selected receives a message when their washing is done.

Do you think that this would be best utilised with a mixture of automations and scripts or just an automation?

Many thanks in advance :slight_smile:

I think two automations would do the trick:

  • One to select who is (about to) wash(ing)
  • One to detect the start and stop of the machine and send a notifitation

To store the resut of the first I would use a input_select.

Would also be possible in a single automation but think two is more logical.

1 Like

That’s really helpful, thank you Timo and have a great day!

excuse me being a Noob Timo but I’m trying to wrap my head around the first automation…

I can see a way of doing this with 3 automations (one for each user) based on the Flic button press however I can’t see how to do if/or type choices within the automations.

Any ideas?

I’m not familiar with the Flic button. But with trigger id’s and a chooser you should be able to wrap it in a single automation.

If you want help with that, please post an automation for a single user and what the triggers for the other users should be.

1 Like

Hi again Timo

Here’s the code I have for the two automations (atm just trying to get it to ping me when washing is done). The first automation runs fine and the second one does message me when I click “run action” however it doesn’t seem to want to trigger the second automation for some reason. Any chance you can help me fix it please?

Automation 1:

  alias: Ed washing on
  description: ''
  trigger:
    platform: event
    event_type: flic_click
    event_data:
      button_name: flic_80e4da786aa8
      click_type: single
  condition: []
  action:
  - service: automation.turn_on
    target:
      entity_id: automation.notify_when_the_washing_machine_cycle_is_complete```

Automation 2:
```- id: 55f349bf8c744924ad5391087c7307e7
  alias: notify when the washing machine cycle is complete
  trigger:
  - platform: numeric_state
    entity_id: sensor.washingmachine_watts
    above: '2'
    below: '2'
  action:
  - service: notify.mobile_app_nokia_3_2
    data:
      title: The washing machine has finished.
      message: It's ready to be emptied```

```sensor:
      washingmachine_watts:
        friendly_name_template: "{{ states.switch.washingmachine.name}} Washing Machine Current <1.5 watts"
        value_template: '{{ states.switch.washingmachine.attributes["Current consumption"] | replace(" W", "") | float <1.5 }}'```

This is incorrect as the automation will only trigger if the numeric_state is above 2 and below 2 at the same time - which will never happen.

Doh and fair point, thanks Andy! I assumed that was transitioning from one to the other.

So I just want below 2?

If you want to detect if the dishwasher is finished after it is being used-

  trigger:
  - platform: numeric_state
    entity_id: sensor.washingmachine_watts
    below: '5'
    for: '00:05:00'

I think 2 is too low. Also, it is better to add for: to anticipate mini power consumption spikes.

Edit: smart meters supposedly does not measure itself. I don’t know why because sometimes I get 1W readings without anything plugged. (Thanks Septillon, probably need to calibrate mine).

1 Like

that’s awesome, thank you Andy! Fingers crossed this now works!

It would be a pretty dumb meter if it would measure that.

But having said that, <2W might be to low depending on the washing machine and the accuracy of the meter.

And what sensor do you use? Most make a separate entity for consumption. The sensor you made does not report Watt but simply true or false depending on it it’s below 1,5W.

Given that this topic’s title is “Automation/script advice”, here’s some advice:

Don’t create automations to turn on/off other automations.

It’s an anti-pattern and usually indicates the controlled automation lacks proper triggers and/or conditions to be self-sufficient.

1 Like

Thank you Taras, I was pretty sure it was “fast and dirty” coding however just finding my way around this system/python.

Would you recommend this using one automation and some scripts or just carefully insert all parameters into the one automation?

Create an input_text to store the phone name of the person who is using the washing machine.

input_text.notify_wash

Create an automation that is triggered by the Flic2 button (similar to the automation you already have) and sets the input_text to the phone name of the person corresponding to the button action. I don’t know how many buttons that gadget has but the example below handles three (easily expanded to whatever quantity you need).

  alias: Identify wash person
  trigger:
  - id: 'ed'
    platform: event
    event_type: flic_click
    event_data:
      button_name: flic_80e4da786aa8
      click_type: single
  - id: 'jane'
    platform: event
    event_type: flic_click
    event_data:
      button_name: flic_abc123
      click_type: single
  - id: 'george'
    platform: event
    event_type: flic_click
    event_data:
      button_name: flic_xyz789
      click_type: single
   action:
  - service: input_text.set_value
    target:
      entity_id: input_text.notify_wash
    data:
      value: >
        {{ 'mobile_app_nokia_3_2' if trigger.id == 'ed' else 'mobile_app_abc' if trigger.id == 'jane' else 'mobile_app_whatever' }}

The automation you are using to monitor the end of the washing cycle can notify the correct person by simply using the value in the input_text.

  action:
  - service: "notify.{{ states('input_text.notify_wash') }}"
    data:
      title: "The washing machine has finished."
      message: "It's ready to be emptied."

You could do all in one automation. But you will need some kind of memory to store the machine started. You could keep one automation running all the time until it finishes but that would break if you restart HA in the mean time (or even reload the automations). That also would not make it easy to store who to notify.

So like @123 I would use a helper. But because it’s a finite set of options I would use a input_select rather than a input_text. But the idea is pretty much the same.

I also would have used a chooser rather than a template because I like the UI. But that is pure preference.

FWIW, that was my initial choice until I realized there was no requirement to manually (and conveniently) change the wash person via the UI (which an input_select would provide).

Even if there was such a requirement, I would imagine it would be to display the person’s name and not the cryptic name of their phone for notification purposes. As a result there would be two conversions required, the first from the button_name to the corresponding wash person’s name for display in the input_select and the second from the input_select’s value to the corresponding phone identifier for notification.

True, but you do that now as well :smiley: So there is no real change accept moving the second convention to the second automation.

And yeah, there is indeed no real need, input_text will work fine. But I think having a input_select would make debugging a little bit easier (when you do want to set it manually). But yeah, with a input_text it is possible to do it in a single conversion at the cost of losing a display name (that displays the name rather then the phone id.

I think you may have misunderstood what I meant by conversion. There’s no second conversion because the template uses the input_text’s value verbatim:

"notify.{{ states('input_text.notify_wash') }}"

If there was a second conversion, it would be converting from the person’s name (i.e. the input_select’s value) to the person’s notification entity (using an if-else chain or a dictionary lookup). That second conversion wouldn’t be needed if the input_select contained the notification entities instead of the person’s name (then it could be used verbatim). However, that makes the input_select less friendly for use in the UI which defeats the purpose of using an input_select in the first place.

You’re overlooking a conversion :wink: You already do a person name to notification id. Otherwise you would have used the notification id as the trigger id :smiley:

I used trigger.id simply to avoid the long-winded use of trigger.event.event_data.blabla. I don’t see how using one or the other constitutes a “conversion” because it’s simply data provided directly by the trigger object. That loose definition of “conversion” implies all triggers perform a “conversion” from one thing to another (which effectively makes it moot as a “conversion”).