I have just started with HA after dropping it due to lack of time.
I am running HA 0.99.3 via HASS.IO which I just installed fresh.
I have added some devices which are fairly straight forward.
However, I am having issues with automation and scripts.
Specifically, I am following this link to allow my remote control to dim a light:
I have copied the script code directly into my scripts.yaml and the automation code into automations.yaml.
However, the HA log shows the following:
Invalid config for [automation]: [initial_state] is an invalid option for [automation]. Check: automation->action->1->initial_state. (See /config/configuration.yaml, line 13). Please check the docs at https://home-assistant.io/components/automation/
Invalid config for [script]: [light_bright] is an invalid option for [script]. Check: script->script->script->light_bright. (See /config/configuration.yaml, line 14). Please check the docs at https://home-assistant.io/components/script/
Here is my scripts.yaml:
# Nursery Light Dimming Script
script:
light_bright:
sequence:
- service: light.turn_on
data_template:
entity_id: light.nursery_night_light
brightness: >-
{% set current = state_attr('light.nursery_night_light', 'brightness')|default(0)|int %}
{% set step = states('input_number.light_step')|int %}
{% set next = current + step %}
{% if next > states('input_number.light_maximum')|int %}
{% set next = states('input_number.light_maximum')|int %}
{% endif %}
{{ next }}
- service_template: >
{% if state_attr('light.nursery_night_light', 'brightness')|default(0)|int < states('input_number.light_maximum')|int %}
script.turn_on
{% else %}
script.turn_off
{% endif %}
data:
entity_id: script.light_bright_pause
light_bright_pause:
sequence:
- delay:
milliseconds: 1
- service: script.turn_on
data:
entity_id: script.light_bright
light_dim:
sequence:
- service: light.turn_on
data_template:
entity_id: light.nursery_night_light
brightness: >-
{% set current = state_attr('light.nursery_night_light', 'brightness')|default(0)|int %}
{% set step = states('input_number.light_step')|int %}
{% set next = current - step %}
{% if next < states('input_number.light_minimum')|int %}
{% set next = states('input_number.light_minimum')|int %}
{% endif %}
{{ next }}
- service_template: >
{% if state_attr('light.nursery_night_light', 'brightness')|default(0)|int > states('input_number.light_minimum')|int %}
script.turn_on
{% else %}
script.turn_off
{% endif %}
data:
entity_id: script.light_dim_pause
light_dim_pause:
sequence:
- delay:
milliseconds: 1
- service: script.turn_on
data:
entity_id: script.light_dim
Here is my automations.yaml
Note that the code from the linked articled is at the buttom of the automations.yaml due to the automations above being created from the GUI:
I think it might be the indentation, because when I started removing some indentation in the automations.yaml I got different errors in the log.
Unfortunately, its not easy for me to remove just two indents automatically as when I hit the delete key twice per line, some lines remove all indents automatically for some reason.
Note: I am using the Configuration Editor addon to make changes to my files.
In regards to the scripts.yaml, this was a straight copy pasteâŚ
Which begs the question, why is the documentation incorrect?
Why would the incorrect indentation be in the code in the documentation?
I am asking because surely other noobs attempting to get HA working would find this frustrating that copying code from official documentation would not work.
Do you know of an easier way to remove incorrect indentation?
It might also be another problem with the scripts.yaml, maybe the indention is correct, thatâs why I wanted that you try it first. In case the documentation is incorrect, we can contact the author afterwards to get it corrected.
I donât know anything about the configuration editor. I use Sublime Text for editing my YAML files and there it is easy to indent to the left or right.
Using Sublime Text editor I was easily able to Unindent the automations.yaml code and now I donât have any errors in the log for that file.
I tried the same for the scripts.yaml and I got no such luck.
I still get:
Invalid config for [script]: [light_bright] is an invalid option for [script]. Check: script->script->script->light_bright. (See /config/configuration.yaml, line 14).
Forgive me for butting in here but the thing that stands out for me is that you have a scripts file (probably script.yaml) so that was included under an include from your configuration.yaml (I use packages so Iâm groping here) from memory that include has a script: header, why are you repeating that header here.?
In your configuration.yaml you probably have something like:
script: !include config/scripts.yaml
If you have this, then you need to remove the first line âscript:â in your scripts.yaml file and probably you have to adjust the indentation as well afterwards. Due to the include in the configuration.yaml file, the system already knows that there are scripts in the scripts.yaml file and therefore the heading âscriptâ is not needed.
You were absolutely right, it was the additional âscript:â. I blatantly copied the code without thinking that it was already in the configuration.yaml include.
My apologies, noob mistake.
So the fix for clearing out the errors was to fix the indentation and remove the redundant âscript:â.
Now I have to figure out why the script is not doing what itâs supposed to.
The automation triggers the script no problem, but the script just turns the light off instead of increasing the brightness.
Even when executing the script from the Overview page, the same issue.
I tested the âlight.turn_onâ service via the service dev tool and specified brightness and it makes the change immediately, so the light is performing as it should.
The linked doco, mentions âinput_numberâ however:
a) I donât know if this is needed
b) It doesnât specify what file I need to put this in (scripts.yaml, configuration,yaml, automation.yaml ?)
Sigh⌠it would be nice if you could just point a dimmer remote to a light or set of lights and it would just do its thing.
I am learning how much effort it takes to get simple things like a dimmer control to dim a light in HA.
Appreciate all your help.
I will keep working on getting this working.
You need the input_number, otherwise this automation will not work.
In your light.turn_on script the brightness will be increased by the number chosen in the input_number, so if you donât have the input_number, the light will just be turned on to the same brightness. You also need the other two input_numbers to define a maximum and a minimum, otherwise youâll probably get an error because if you are at full brightness and you want to increase it more, it doesnât work.
- service: light.turn_on
data_template:
entity_id: light.nursery_night_light
brightness: >-
{% set current = state_attr('light.nursery_night_light', 'brightness')|default(0)|int %}
{% set step = states('input_number.light_step')|int %} #the step to increase comes from input_number.light_step
{% set next = current + step %}
{% if next > states('input_number.light_maximum')|int %}
{% set next = states('input_number.light_maximum')|int %}
{% endif %}
{{ next }}
About where to put the input_numbers, Iâd suggest to read this:
You can put it in the configuration yaml, or you can put it in itâs own package or you can do the same like you did for the scripts and add input_number: !include config/input_number.yaml to your configuration.yaml and create a new file input_number.yaml. It all depends on how you want to organize your system.
Sorry, but what doesnât help a beginner is having 16 different ways of doing the same dang thing.
With different indenting required for different configurations.
I recommend that you go the packages route
EVERYTHING I have is based on packages and EVERYTHING is in a common format.
I could send you âmy package for an alarm clockâ (ficticious example) and everything you need is in the same package, the only thing youâd need to change is the name of the lamp/radio/pnumatic bed tipper that it acts upon.
@Mutt , I am very interested in any way I can standardise my configuration as I get confused at the best of times.
I googled âhome assistant packagesâ and found the main article, however, I am still having trouble understanding how they work.
Could you explain in laymanâs terms how packages work?
Ie. Do I still need to put code into configuration.yaml, scripts.yaml, automation.yaml etc?
Are you saying that packages have one set of indentation rules?
Does HA have a âbest practiceâ way of doing things to keep things clean and tidy? or is it a bit of the wild west where anything goes?
A package combines multiple sensors, scripts whatever into one file.
E.g. you have an office with a media player and a door sensor. Without packages you would add this to your configuration.yaml
Now if you have more rooms and more sensors, media players etc. you add them to the configuration.yaml and it grows and grows and becomes more and more unorganized.
With packages you can separate the configuration.yaml file into multiple files. For the above example you could create a new folder called âpackagesâ and put a file called office.yaml there. Add this to the office.yaml file:
Now if you have a new room, you just create a new file in the packages folder and add your sensors etc. there. This way your configuration.yaml stays small and organized. You donât need to separate it by room, you can separate it however you like. You can have a package that includes everything related to your security system and call it security.yaml or whatever you like.
Thereâs no âbest practiceâ for this, however a lot of people put their config into packages as I described above.
I splitted up my conifguration into packages if you want to get some inspiration you can check out my GitHub.
Burningstone, a nice example and description.
But Joshua, thereâs as many ways to organise packages as anything else, so you may not want to do it by room. It doesnât matter though as they all co-exist. And youâll probably change things as time goes by.
Itâs up to you and you donât have to follow our recommendation, after all, its just our opinion