I know this is going to be controversial.
I have spent the last 2 days trying to write an automation that triggers on a change of input_select and actions the assigning of a value to an input_number. The code examples for trigger are inconsistent as are the ones for condition and action.
Given that some people use directory include then this may require the use of a header line similar to a bash or python script #automation or #script or similar just so the editor knows what it is looking at.
Here is an example of the code I wanted to write (the uncommented bits) :-
- id: light_tod_set_mstr_br1 # WOT
alias: Set Master Brightness On ToD1
trigger:
plateform: state
entity_id: input_select.slct_light_tod
to: 'Night'
# trigger: # taken from :- https://home-assistant.io/cookbook/perform_actions_based_on_input_select/
# platform: state # ditto
# entity_id: input_select.lullaby # ditto
# to: "Rain" # ditto, have tried Night, 'Night' and "Night" (values are Night, Day, Dusk)
action:
- service: input_number.set_value
data:
entity_id: input_number.num_light_mstr_value
value: 64
# action: # taken from :- https://home-assistant.io/components/input_number/
# service: input_number.set_value # ditto
# data_template: # ditto, okay it's not a template so just replace with data: ???
# entity_id: input_number.target_temp # ditto, tried this, tried placing above data: with less indent
# value: '{{ trigger.payload}}' # ditto, as data: used just number 64, also tried '64' and "64"
The errors I was getting in the log were baffling and not helpful.
So I made a copy of my automations.yaml file expecting it to be destroyed when using the automation editor (it was)
So I emptied the file and started again (clean sheet)
I placed the trigger - okay
I went to place the action and stated the service was input_number.set_value
The next thing that I had to fill in was service data - Whatās that ???
I tried to set an entity_Id - no go
Okay do I set a value and then it asks for the entity then ? - no
This is what the automation editor produced and to be honest I canāt make head nor tail of it
- action:
- service: input_number.set_value
alias: Set Master Brightness On ToD1
condition: []
id: '1513271551107'
trigger:
- entity_id: input_select.slct_light_tod
platform: state
to: Night
Okay, so the ref is ā1513271551107ā, but why does the action come first at to level ?
The trigger seems fine but ā¦
So what I was thinking is that you canāt enter anything direct, just pick elements as you go.
Select Insert point
Insert - (top level so only New Automation or Comment available)
Okay you picked automation - What to you want to ref (id) it as ? and whatās its alias ?
Okay Now you have to have a Trigger so thatās a given (all appropriately indented)
So what platform ?
etc. etc.
Iām not saying itās an easy thing to do, but look at all the issues with newbies (Iām one) and code, spacing, formatting and syntax And that is fundamental to getting anything done and how much of this forum is going over these basics ?
How many times have you seen leading dashes, oh and it appears you can leave them out sometimes (well at least the parser doesnāt complain)
The following is a direct ācopyā from the HA documentation website :-
trigger:
platform: sun
event: sunset
action:
service: light.turn_on
entity_id:
- light.kitchen
- light.living_room
data:
brightness: 150
rgb_color: [255, 0, 0]
So it seems that once you state a service, you can merely list the affected entities and then shove the required change and that will have it apply to ALL of them ā¦ So how come then next bit of code does not work ? (yes, I know itās a script)
scr_turnofftodbool:
sequence:
- service: input_boolean.turn_off
entities:
input_boolean.boo_light_night
input_boolean.boo_light_day
input_boolean.boo_light_dusk
I just think if the appropriate lego blocks are fed people in the right order, then they will have a better chance.
Let us know what you think, though this probably more to the less experienced end of the scale ; - ))) (me)
Mutt