I have two simple scripts configured YAML files. One appears in list of Services, the other does not. The system does not report any error messages. What have I done wrong?
Script that works:
swimmingpool_package_1:
script:
start_swimmingpool_cleaning:
alias: Start Swimming Pool Cleaning
sequence:
service: script.swimmingpool_cleaning
data:
cycle_count: 5
# mode: single
Script that does not work:
swimmingpool_package_2:
script:
swimmingpool_cleaning:
alias: Swimming Pool Cleaning
sequence:
repeat:
while: "{{ cycle_count > 0 }}"
sequence:
cycle_count: "{{ cycle_count - 1 }}"
service: notify.persistent_notification
data:
message: "Pool Cleaning"
title: "Pool Cleaning Notification"
# mode: single
Example trying to CALL SERVICE:
Hi Stephen,
No, I am not using the UI to create the scripts - I am using the File editor.
Each script is in a separate YAML package named as:
/homeassistant/packages/swimmingpool/swimmingpool_package_1.yaml
and
/homeassistant/packages/swimmingpool/swimmingpool_package_2.yaml
Hi Stephen,
I do not know how to create a Package YAML using the UI!
I do not even know how to use the UI to create a Service like my two examples!
I am UI challenged and YAML challenged.
In this day-and-age I would hope to be using an object-oriented language like C#.
I think that YAML has been an unfortunate language choice for configuration - but that is what it is.
I would appreciate any pointers on using the UI for Scripts, particularly with Scripts in Packages if that is possible.
I am surprised either works. Based on the example in the documentation, you should repeat the folder and file name in the file itself, separated by an underscore.
But as a caveat, I don’t use this method so this is just a guess. I use the !include_dir_named method for packages which allows me to name the files however I please, and the first heading in the file is the same as if it were in configuration.yaml
Thanks Ric, I tried your suggestion but it had no affect.
I would love to see an article discussing best practice for naming things when working with Packages!
Your script is malformed. Variables have to be defined with the variables key, and once you add more than one item in a sequence it must be a list. It’s good habit to make it a list when it’s only 1 item as well.
Thanks Rick,
I have made the changes you suggested, and the Script is now found!
But I am having troubles with “Variables”. You stated “Variables have to be defined” but the documentation at “counted repeat” seems to indicate otherwise.
Two related questions? When I test this script it causes an infinite loop which creates thousands of notifications!
Is there a way to dismiss ALL notifications?
Is there a way to halt a runaway script, other than rebooting the HA computer?
A counted repeat is different from a “while” loop. In a counted repeat, count is a special key.
You can use a notification_id so that notifications get overwritten rather than duplicated. To fix the problem you already have, you can use the service call to dismiss all:
YAML is not a programming language, but it is replacing XML as a “more human readable” serialization language like XML and JSON. After a year of writing YAML files for my Home Assistant, I still don’t get it. Someday it will grok.
You probably shouldn’t use packages if you don’t understand YAML.
I find the UI easier to use. Go to Settings → Automations and Scenes → scripts → Add Script, then follow the prompts. Don’t forget to click on “save script”.
You can test/run the script from inside the UI. You can also see or edit the YAML code that the UI generates.
You’re overwriting a supplied variable. Automations & variables do not allow this.
You made up a field outside variable action and just added it to a random service call. That’s not allowed. Yaml fields are rigid, there will be errors in your logs about extra fields not allowed cycle_count
Hi Stephen,
Thanks. Nice to know how manage Scripts from the UI.
Unfortunately for me, it seems to not understand Packages which I am using. I get the following error:
Visual editor is not supported for this configuration
Templates not supported in visual editor
You can still edit your config in YAML.
Hi Petro, Thanks. Your three comments are very helpful. I tried “Count” and it does what I want.
The useless notifications in the script are my way of debugging. Now I have the script being found I will put some useful actions in there.