I’ve been struggling with this for a little too long. Thought I’d put it to the community as I can’t string it together from the documentation…
The error message showing in the log is
2017-10-15 05:34:29 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [condition] is an invalid option for [script]. Check: script->script->timed_light->condition. (See /config/configuration.yaml, line 144). Please check the docs at https://home-assistant.io/components/script/
2017-10-15 06:13:32 ERROR (MainThread) [homeassistant.config]
Invalid config for [script]: [condition] is an invalid option for [script].
Check: script->script->timed_light->sequence->0->condition.
(See /config/configuration.yaml, line 144).
Please check the docs at https://home-assistant.io/components/script/
I do mine with the conditions in the automation rather than in the scripts…
- alias: 'Turn on kitchen light when there is movement and the sun is down'
trigger:
- platform: state
entity_id: switch.pikitchenpir, switch.tellkitchenpir
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: 'down'
- condition: state
entity_id: input_boolean.detect_motion
state: 'on'
action:
- service: script.turn_on
entity_id: script.timed_kitchen_lamp
Then in script.yaml
timed_kitchen_lamp:
alias: "Turn on kitchen light and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_kitchen_lamp_off
- service: light.turn_on
entity_id: light.kitchen_ceiling_light
data:
brightness: 180
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_kitchen_lamp_off
timer_kitchen_lamp_off:
alias: "Turn off kitchen light after 15 minutes"
sequence:
- delay: 00:15:00
- service: light.turn_off
data:
entity_id: light.kitchen_ceiling_light
I had trouble getting conditions to work inside a script also. I’m adding the configuration that worked for me to this thread to hopefully save someone else all the trouble I had.
Unlike your problem - using ‘and’ conditions - I wanted to use multiple separate conditions in my sequence of actions - and have the script stop when one of them was true. Keep in mind that this was just a script to test for the correct syntax as opposed to one that actually does anything useful.
The script runs when activated and turns on the North Office Light.
If the lower stairway light is off, the script ends. If it’s on, the script continues and turns on the South Office Light.
If the upper stairway light is off, the script ends. If it’s on, the script continues and turns on the Upstairs Hallway light.
Most of the trouble I had making this work was with the indents. There didn’t seem to be any examples of multiple conditions in a script - and those posts that I found asking about it (like this one) seemed to end with some advice to use automations instead of scripts. Anyhow - hope this example helps someone. It’s tested and working with HomeAssistant 0.59.2
I was having just this problem and found this thread while trying to solve it. I eventually found the solution so thought I’d post it back here to help anyone else struggling with this.
Despite what you might think looking at the documentation on ‘condition’, in a script it appears you can put the logical operator on the line with the first ‘condition’ statement. ie
sequence:
- condition: and
conditions:
- condition: state
entity_id: switch.entrance_light
state: off
- condition: sun
state: above_horizon
That should work just fine. (But you also need to put quotes round the state values - e.g. state: ‘off’)
Hi Prejury, I am trying to run a simple script similar to yours. have two conditions and if they are both true, turn golf light on. I have been trying for a while and couldn’t get it working. just wonder if you can show me your working script? it will be much appreciated if you can. My script as shown below.
Hi perjury, what is the (- condition: or) for? from what I understand by reading the code, if input_boolean.notifyphil is ON AND phil is not home. Send phil a message. is that correct? you were correct with switch.golf as well.
correcting_living_tv_status1:
alias: 'Correct Living TV Status To Off'
sequence:
- condition: state
entity_id: binary_sensor.living_tv_status
state: 'off'
- condition: state
entity_id: input_boolean.living_tv_power_bool
state: 'on'
- service: input_boolean.turn_off
entity_id: input_boolean.living_tv_power_bool
correcting_living_tv_status2:
alias: 'Correct Living TV Status To On'
sequence:
- condition: state
entity_id: binary_sensor.living_tv_status
state: 'on'
- condition: state
entity_id: input_boolean.living_tv_power_bool
state: 'off'
- service: input_boolean.turn_on
entity_id: input_boolean.living_tv_power_bool