I have an automation for my washing machine that does a few things.
One of the last steps it has is to turn on a light once the washing is done. All works well and no issues.
What I want to do is have the part where the light turns on only run if someone is home (we all use the HA app on our mobiles). If nobody is home just wait till someone is and then turn on the light and finish off that part of the automation.
I have tried a few things but I can make it work so will appreciate any assistance. This the code:
alias: "Helper: Set Dishwasher Status to Unemptied"
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.smartpower_13_power
for: "00:01:00"
below: "0.3"
condition:
- condition: state
entity_id: input_select.dishwasher_status
state: Running
action:
- service: notify.mobile_app_mnms24ultra
data:
message: Dishwasher has finished its washing cycle
title: 🏁 Dishwasher is done 🏁
data:
channel: OfflineDevices
ttl: 0
priority: high
color: green
- service: input_select.select_option
data:
option: Unemptied
target:
entity_id: input_select.dishwasher_status
- service: light.turn_on
target:
entity_id: light.ledlight_1
data:
color_name: blue
transition: 5
mode: single
Just a note that this is also available in the visual editor, so you can try that when you are unsure about the intendations, order in the code etc. It’s in the “then do” section, “add construction block”.
Huh, learn something every day with HA. Follow @Hellis81’s suggestion, corrected in my earlier post.
@MnM — it is worth trying to understand what these error messages are telling you. They may look obscure, but that’s actually a pretty clear message.
Message malformed:
expected str for dictionary value @
data['action'][2]['if'][0]['state']
It’s saying “look at your action block, third (because we count from 0) item, at the if block, at the first (and only) item inside it, then at the state: I was expecting a string value (str) but didn’t get one”.
If you’re unsure what a string is, and why 0 isn’t one, read up on the various data types here (linked from Developer Tools / Template in your system):
Thank you all for your assistance.
I have implemented it (using Troon’s code) and it seems to be working ok. Need to test and see what will happen when nobody is home, but when everyone is home is works fine).
Also thanks for explaining the error to me. It is good to know what they mean.
I am trying to get it to get this script to the next level now.
Basically I have 2 similar scripts (one for dishwasher an one for washing machine) using the same led light. One turns the led lights blue the other green.
All is good when the scripts run individually. However, if both run the same time the last script to finish will override the color of the led light. I am looking now to have another condition where the last script to finish will check the status helper of the other script and if the status = unemptied then make the led light RGB.
The 2 status helper used in the 2 scripts are:
input_select.dishwasher_status
and
input_select.washing_machine_status
So the dishwasher script will check the input_select.washing_machine_status to see if is = unemptied. If it is then will turn on RGB on the led light (or an effect that I have defined via ESPHome on my led light), but still use the conditions made above - if user not home do nothing till user home.
If input_select.washing_machine_status != unemptied then proceed with script with the solution above.
I did try myself to have a go, but I think I am still too green to make it happen, so I am in need of your assistance again
It’s always helpful to post what didn’t work and the entire YAML. It makes it easier for folks to see all the logic and have the names of your actual sensors and everything. That said, let’s give this a go. At the end of the dishwasher YAML put (you should fix the indents below so they match with your YAML - another reason to post the entire YAML):
@pkscout Apologies - yes i should have posted the code. here it is, below.
So the code you have posted will not invalidate the home/not home portion of the script below? Will just run in addition to it?
alias: "Helper: Set Dishwasher Status to Unemptied"
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.smartpower_13_power
for: "00:01:00"
below: "0.3"
condition:
- condition: state
entity_id: input_select.dishwasher_status
state: Running
action:
- service: notify.mobile_app_mnms24ultra
data:
message: Dishwasher has finished its washing cycle
title: 🏁 Dishwasher is done 🏁
data:
channel: OfflineDevices
ttl: 0
priority: high
color: green
- service: input_select.select_option
data:
option: Unemptied
target:
entity_id: input_select.dishwasher_status
- if:
- condition: state
entity_id: zone.home
state: "0"
then:
- wait_for_trigger:
- platform: state
entity_id: zone.home
from: "0"
- service: light.turn_on
target:
entity_id: light.ledlight_1
data:
color_name: blue
transition: 5
mode: single
with the code I provided, I think it will do what you want. The only question mark for me is the RGB color. Is that a color the LED recognizes that causes it to rotate colors?