Condition under action problem

For some reason I cannot explain the below automation does not work (error created by the condition under the action). The idea of the automation is that the house goes to sleep and only when a door is left open it also warns me about that open door.

The condition under the action is a working condition in my alarm automation so it is somehow related to the nesting of the condition under that action.

Error:
2017-06-27 09:40:57 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->action->2->condition. (See /home/hass/.homeassistant/configuration.yaml, line 260). Please check the docs at https://home-assistant.io/components/automation/

  - alias: "Sfeeruit"
    trigger:
      - platform: state
        entity_id: input_boolean.sfeeruit
        from: "off"
        to: "on"
    action:
      - service: tts.google_say
        entity_id: media_player.family_room_home
        data_template:
          message: "Goognight and sleep well"
          cache: false
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.sfeeruit
      - condition:
        - condition: state
          entity_id: 
            - binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0
            - binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0
            - binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0
            - binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor_33_0
            - binary_sensor.sensative_strips_sensor_8_0
            - binary_sensor.everspring_hsm02_doorwindow_sensor_sensor_6_0
          state: "on"
      - service: tts.google_say
        entity_id: media_player.family_room_home
        data_template:
          message: "Attention, door left open"
          cache: false
      - service: notify.mypushover
        data_template:
          message: "{{ trigger.to_state.attributes.friendly_name }}"
          title: "Alarm"

I think that:

  - condition:
    - condition: state
      entity_id: 

just needs to be

- condition: state
  entity_id: ...

(with correct indentation).

The syntax you tried is only used when nesting conditions (I think), e.g.:

- condition:
  conditions:
  - condition: state
    ....
  - condition: template
    ... 

or something like that.

Sebastian

I had this originally and just tried again (code below for completness) but same error.

  - alias: "Sfeeruit"
    trigger:
      - platform: state
        entity_id: input_boolean.sfeeruit
        from: "off"
        to: "on"
    action:
      - service: tts.google_say
        entity_id: media_player.family_room_home
        data_template:
          message: "Goognight and sleep well"
          cache: false
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.sfeeruit
      - condition: state
        entity_id: 
          - binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0
          - binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0
          - binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0
          - binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor_33_0
          - binary_sensor.sensative_strips_sensor_8_0
          - binary_sensor.everspring_hsm02_doorwindow_sensor_sensor_6_0
        state: "on"
      - service: tts.google_say
        entity_id: media_player.family_room_home
        data_template:
          message: "Attention, door left open"
          cache: false
      - service: notify.mypushover
        data_template:
          message: "{{ trigger.to_state.attributes.friendly_name }}"
          title: "Alarm"

It’s not the solution but this workaround might be more interesting though as it allows you to get directly the name of the opened window (not sure about YAML syntax)

action:
      - service: tts.google_say
        entity_id: media_player.family_room_home
        data_template:
          message: >-
            Goognight and sleep well
            { % if is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
            Attention, the XXX window is open
            { % elif is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
            Attention, the XXX window is open
            { % elif is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
            Attention, the XXX window is open
            { % endif %}
          cache: false
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.sfeeruit
      - service: notify.mypushover
        data_template:
          message: "{{ trigger.to_state.attributes.friendly_name }}"
          title: "Alarm"

As a bonus, I would also change the line > goodnight and sleep well to add more character to the tts :smiley:

message: >-
  {{ [
  "Good night and sleep well. " ,
  "See you soon. " ,
  "Have a nice dream. " ,
  "Hush baby don't say a word, and nevermind those words you heard, it's just the beast under your bed, in your closet, in your head... "
  "Basically anything you want it to say when you go to sleep "
  ] |random }}

The problem seems to be the list of entities under entity_id for the condition.
I tried it with:

entity_id: binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0

(one line)
and it passed the configcheck.
You probably need to do use one condition per sensor and and outer or-condition.

Sebastian

Like this solution so directly implented. However get an error. As I’m really bad in JINJA templating I’m not sure what is wrong:

017-06-27 12:51:32 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['action'][0]['data_template']['message']. Got None. (See /home/hass/.homeassistant/configuration.yaml, line 260). Please check the docs at https://home-assistant.io/components/automation/

action:
  - service: tts.google_say
    entity_id: media_player.family_room_home
    data_template:
      message: >-
        Goognight and sleep well
        {{ % if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0', 'on') %}}
        Attention, the door to the front garden is open
        {{ % elif is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0', 'on') %}}
        Attention, the pantry door is open
        {{ % elif is_state('binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0', 'on') %}}
        Attention, the main kitchen door is open
        {{ % elif is_state('binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor_33_0', 'on') %}}
        Attention, terras door in room Gitte is open
        {{ % elif is_state('binary_sensor.sensative_strips_sensor_8_0', 'on') %}}
        Attention, the door in TV room is open
        {{ % elif is_state('binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0', 'on') %}}
        Attention, the door in the office is open
        {{ % elif is_state('binary_sensor.__sensor_25_0', 'on') %}}
        Attention, the frontdoor is open
        {{ % endif %}}
      cache: false

Mhh, weird but thanks! The code I used was identical to a trigger in another automation. Seems condition works different then.

My bad, try with only one pair of { } and not {{ … }}

Or try this, it think both solutions will do the trick

message: >-
  Goognight and sleep well
  {{ 'Attention, the door to the front garden is open' if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0', 'on') }}
  {{ 'Attention, the pantry door is open' if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0', 'on') }}
cache: flase

Confirming that the second solution works! Nice. Thanks

What about the first one?

Could not get that to work (the one pair of {}). Same error if I remember correctly.