Condition: vs. platform: in automation. Need some documentation

So I upgraded to .19 and started getting the following error.
homeassistant.components.automation: Please switch your condition configuration to use ‘condition’ instead of ‘platform’.

The blog on the new release is not very clear. Doing a search/replace of platform: with condition: doesn’t make sense and also generates new errors.
It would also lead to condition being used recursively.

# Turns on lights at sunset
- alias: 'Rule 3 Welcome Home light in kitchen'
  trigger:
      platform: state
      entity_id: binary_sensor.stairwell_motion_sensor_4
      from: 'off'
      to: 'on'
  condition:
    - platform: state
      entity_id: binary_sensor.basement_motion_sensor_5
      state: 'on'
    - platform: sun
      after: sunset
  action:
    service: light.turn_on
    entity_id: light.kitchen_dimmer_level_9

Under condition: replace all platform with condition :
https://home-assistant.io/getting-started/scripts-conditions/

#Turns on lights at sunset
alias: 'Rule 3 Welcome Home light in kitchen'
trigger:
  platform: state  
  entity_id: binary_sensor.stairwell_motion_sensor_4
  from: 'off'
  to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.basement_motion_sensor_5
    state: 'on'
  - condition: sun
    after: sunset
action:
  service: light.turn_on
  entity_id: light.kitchen_dimmer_level_9
1 Like

just replacing platform when nested under condition generates lots of errors.
Here is my new automation.yaml file.

### Automation ###
#automation:

# Turns on lights at sunset
- alias: 'Rule 1 Light on in the evening'
  trigger:
    # Prefix the first line of each trigger configuration
    # with a '-' to enter multiple
    - platform: sun
      event: sunset
      offset: '-00:10:00'
  action:
    service: homeassistant.turn_on
    entity_id: switch.front_step_light_switch_3

- alias: 'Rule 2 Light off in the morning'
  trigger:
    - platform: sun
      event: sunrise
      offset: '-00:19:00'
  action:
    service: homeassistant.turn_off
    entity_id: switch.front_step_light_switch_3

# Turns on lights at sunset
- alias: 'Rule 3 Welcome Home light in kitchen'
  trigger:
      platform: state
      entity_id: binary_sensor.stairwell_motion_sensor_4
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: binary_sensor.basement_motion_sensor_5
      state: 'on'
    - condition: sun
      after: sunset
  action:
    service: light.turn_on
    entity_id: light.kitchen_dimmer_level_9

#automation 2:
# Vacation mode for Kitchen light
- alias: 'Rule 4 Vacation Mode for Kitchen ON'
  trigger:
    platform: sun
    event: sunset
    offset: "-00:30:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: light.turn_on
    entity_id: light.kitchen_dimmer_level_9

# Vacation mode for Kitchen light
- alias: 'Rule 5 Vacation Mode for Kitchen OFF'
  trigger:
    platform: sun
    event: sunset
    offset: "+02:35:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: light.turn_off
    entity_id: light.kitchen_dimmer_level_9

# Vacation mode for Living Room light
- alias: 'Rule 6 Vacation Mode for Living Room ON'
  trigger:
    platform: sun
    event: sunset
    offset: "-00:38:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.living_room_switch_7

# Vacation mode for Living Room light
- alias: 'Rule 7 Vacation Mode for Living Room OFF'
  trigger:
    platform: sun
    event: sunset
    offset: "+01:25:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_off
    entity_id: switch.living_room_switch_7

# Vacation mode for Great Room light
- alias: 'Rule 8 Vacation Mode for Great Room ON'
  trigger:
    platform: sun
    event: sunset
    offset: "+00:20:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.great_room_lights_switch_6

# Vacation mode for Great Room light
- alias: 'Rule 9 Vacation Mode for Great Room OFF'
  trigger:
    platform: sun
    event: sunset
    offset: "+03:07:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_off
    entity_id: switch.great_room_lights_switch_6


# Vacation mode for Bedroom Room light
- alias: 'Rule 8 Vacation Mode for Bed Room ON'
  trigger:
    platform: sun
    event: sunset
    offset: "+02:35:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.master_bedroom_switch_8

# Vacation mode for Great Room light
- alias: 'Rule 9 Vacation Mode for Great Room OFF'
  trigger:
    platform: sun
    event: sunset
    offset: "+03:50:00"
  condition:
    condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
    service: switch.turn_off
    entity_id: switch.master_bedroom_switch_8

=======================
Error log

Home Assistant
0.19

Developed by a bunch of awesome people.

Published under the MIT license
Source: server — frontend-ui — frontend-core

Built using Python 3, Polymer 1.4.0, NuclearJS 1.3.0
Icons by Google and MaterialDesignIcons.com.

The following errors have been logged this session:

16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:04:50 homeassistant.components.automation: Please switch your condition configuration to use 'condition' instead of 'platform'.
16-05-07 22:05:13 netdisco.ssdp: Found malformed XML at http://10.0.1.211:9080: status=ok
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'
16-05-07 22:16:51 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 801, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/discovery.py", line 55, in discovery_event_listener
    if event.data[ATTR_SERVICE] in service:
KeyError: 'service'

doing a global replace of platform with condition generates this error.

16-05-08 08:02:30 homeassistant.bootstrap: Invalid config for [automation]: required key not provided

Difficult to read without formatting :neutral_face:
Please edit or post it again formatted so we can find errors

automation.yaml (3.6 KB)

Thanks! Here is my automation.yaml file which generates the slew of errors. The only change from version 0.18.2 was to change the nested platform statements to condition after upgrading to version 0.19.

original-automation.yaml (3.6 KB)

This was my original automation config from v0.18.2

Looks to me like you have got your formatting wrong on the first few automations

the ‘-’ prefix should line up with ‘trigger’ on the next line (not 2 spaces in). Also the ‘-’ prefix is necessary only for multiples

I usually like to split each automation into a separate yaml file so I know exactly which one is causing issues. Also google ‘yaml parser’ & test any code before uploading to HA

Thanks. They all passed the yaml parser, but apparently the 0.19 release is a bit more finicky. So clearing out the extra spaces (once again) did the trick and also allowed me to replace the appropriate ‘platform:’ statements with ‘condition:’

I thought you couldn’t break up the sections into multiple include files.
So do you set this up like this?:

#configuration.yaml file

automation:
!include 1st-automation.yaml
!include 2nd-automation.yaml
!include 3rd-automation.yaml

configuration.yaml has…

automation: !include folder/automation.yaml

Then automation.yaml (which is in a sub-folder along with the actual automations too) has…

- !include sunset.yaml
- !include bedtime_week.yaml

Then for each new automation just add a line to the automation.yaml

Your config seems fine. The errors in discovery you are getting are related to a malformed discovery event.

I’ve had that malformed discovery problem with my Roku3 for quite a while and never had any of these other problems.

As people are discovering how the new features of 0.19 work, fixes to the documentation are appreciated.

I also got stuck on this one, notably with “or” conditions. In case it helps, a lot messing about using good ol’ guessing and the trial and error method (based on an example) led me to the following which I finally got HA to accept. (I haven’t seen if it actually works yet!)

automation 2:
   alias: Turn on lights when arriving
   condition: or
   conditions:
      - condition: time
        before: 06:00
      - condition: time
        after:  22:00
   trigger:
      platform: template
      value_template: "{% if is_state('device_tracker.1000180', 'home') %}true{% endif %}"
   action:
      service: homeassistant.turn_on
      entity_id: group.Arrival

Try quoting the time ( ‘06:00’ and ‘22:00’ ). Maybe the colon is the reason that it fails.

I have updated to 0.19 and replaced “platform:” with “condition:” on my automations. I get no errors but automation does not get triggered.

I would like to see all the examples updated with their new working configs. Then, after getting those as examples, I can upload my configs also.

@sfiorini My github repo examples are updated for 0.19.4. Tested and running. If you have any question…

https://github.com/danichispa/homeassistant

Actually, @danichispa, I started with quotes and removed them thinking that the single-quote might be posing a problem. There is no difference in behavior based on the quotes.

I have to confirm the same situation as @sfiorini… The warnings tell you that condition_type is deprecated and to change platform to condition. When doing so using the syntax above, HA accepts it in the configuration file, but the automation does not run. The log then contains the following error, and the automation block is apparently not loaded.

ERROR:homeassistant.bootstrap:Invalid config for [automation]: invalid list value @ data[‘condition’][0] (See /Users/myname/.homeassistant/configuration.yaml:82)

The only way to make it work is to go back to condition_type and platform and to live with the warnings. (It seems that the code for the configuration parser and for the actual loading or execution are out of sync in this update.)

thank you @danichispa!! You were of great help. I got it all figured out.