A few things.
First, you do not need to “turn_off” script.easyplus_state. Since it has no delay/wait statements, it will never turn on.
Secondly, each script is a separate thing. And each “service” in the “sequence” of a script is executed by a call (which means Home Assistant asks it to run, and then moves on, without waiting for it to finish). So, this explains why switch.turn_on is running before script.easyplus_state has finished.
You can achieve your goal in a few ways:
- move the “delay” into dishwasher_turn_on. Use a template for the delay time. Something like…
delay:
seconds: >-
{% if is_state('switch.easyplus', 'off') %}
17
{% else %}
0
{% endif %}
To make this option work, you’ll likely need to add a delay to the top of script.easyplus_turn_on so that the switch is still “off” when this part of the sequence is evaluated (since it’s happens after your request to turn it on). You may also need to increase the delay a bit from 17 in order to give enough time for things to happen.
- You can use a wait_template and a template binary_sensor to ensure that the switch has been on for 17 seconds and get rid of the delay in script.easyplus_turn_on entirely.
First you’ll need a binary_sensor.template:
binary_sensor:
- platform: template
sensors:
easyplus_on_17s:
value_template: "{{ is_state('switch.easyplus','on') }}"
delay_on:
seconds: 17
Then modify your automation to look like this:
dishwasher_turn_on:
sequence:
- service: script.easyplus_state
- wait_template: "{{ is_state('binary_sensor.easyplus_on_17s', 'on') }}"
timeout:
seconds: 22 #give it 5 extra seconds in case of delays
continue_on_timeout: false
- service: switch.turn_on
entity_id: switch.stp_kitchen_equipment
- service: notify.merwone
data_template:
message: '
3 dishwasher {{states.switch.stp_kitchen_equipment.state}}'
Personally, I would go with option 2. Additionally, I would get rid of script.easyplus_state and script.noop entirely and just add a condition to the top of script.easyplus_turn_on. Like:
easyplus_turn_on:
sequence:
- condition: state
entity_id: switch.easyplus
state: "off"
- service: notify.merwone
data_template:
message: "1 easyplus is {{states.switch.easyplus.state}} - turning on"
- service: switch.turn_on
entity_id: switch.easyplus
The logic would be as follows…
Your automations and such will only ever call script.dishwasher_turn_on
The first thing the script does it turn on the easyplus using script.easyplus_turn_on. This script only turns it on if it’s not already on. If your device isn’t changed in any way by turning it on again, you could replace the call to this script with a simple switch.turn_on service call instead.
Next, it waits for the switch to be on for 17s (as helped by the binary_sensor template).
Finally, it turns on stp_kitchen_equipment.