Automation and Condition do not work

I’m trying an automation with conditions, but I always get an error message that it’s not correct.
The various actions should be executed depending based on settings of the
input boolean (input_boolean.enable_sensor_notify, input_boolean.enable_sensor_alexamessage).

  1. The “notification to homeassitant” should only be sent if “input_boolean.enable_sensor_notify” is on.
  2. The “notification to all Amazon devices” should only be sent if “input_boolean.enable_sensor_alexamessage” is on.
  3. All other actions should always be performed.

ERROR MESSAGE

Invalid config for [automation]: [service] is an invalid option for [automation]. Check: automation->action->2->conditions->1->service. (See ?, line ?). 

AUTOMATION

## ----------------------------------------------------------------------------------
## BITIWEND RF SENSOR WITH SONOFF RFBRIDGE: POST BOX
## ---------------------------------------------------------------------------------
  - id: postbox_sensor
    alias: postbox_sensor
    initial_state: true
    trigger:
      - platform: mqtt
        topic: "tele/rfbridge/RESULT"
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.RfReceived.Data == "21A8F3" }}'

    action:
      ## ----------------------------------------------    
      ## publish the postbox sensors state: OPEN
      ## ----------------------------------------------    
      - service: mqtt.publish
        data_template:
          topic: "security/sensor/postbox"
          retain: false
          payload: >-
           {
             "timestamp": "{{ now().strftime('%Y-%m-%d %H:%M:%S') | string}}",
             "state": "open",
             "location": "postbox",
             "sensor": "{{ trigger.payload_json.RfReceived.Data | string }}",
             "sync": {{ trigger.payload_json.RfReceived.Sync | string}}
           }
      
      ## ----------------------------------------------     
      ## set the boolean input state Postbox OPEN   
      ## ----------------------------------------------    
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.sensor_postbox

      - condition: or 
        conditions:  
          ## ----------------------------------------------
          ## send notification to homeassitant gui
          ## ----------------------------------------------
          - condition: state
            entity_id: input_boolean.enable_sensor_notify
            state: 'on'    
          - service: persistent_notification.create
            data:
              message: "Postkasten wurde um {{ now().strftime('%Y-%m-%d %H:%M:%S') }} geöffnet !"
              title: "Security Postkasten"
  
          ## ----------------------------------------------  
          ##  send notification to all amazon devices
          ## ----------------------------------------------      
          - condition: state
            entity_id: input_boolean.enable_sensor_alexamessage
            state: 'on'               
          - service: media_player.alexa_tts
            data:
              entity_id: 
                - media_player.esszimmer          ## echo show 2nd Gen
                - media_player.wohnzimmer         ## echo dot 2nd Gen
                - media_player.office             ## echo 2nd Gen
                - media_player.bad                ## echo 1st Gen
                - media_player.fitnessraum        ## echo dot 2nd Gen 
              message: "Hausmeister meldet, Trara, Trara, die Post ist da, es ist etwas im Postkasten."

      ## ----------------------------------------------
      ## set the boolean input state Postbox COSED   
      ## ----------------------------------------------
      - delay: '00:01:00'   ## postman need's time
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.sensor_postbox
      ## ---------------------------------------------- 
      ## publish the postbox sensors state: CLOSED 
      ## ----------------------------------------------  
      - service: mqtt.publish
        data_template:
          topic: "security/sensor/postbox"
          retain: false
          payload: >-
           {
             "timestamp": "{{ now().strftime('%Y-%m-%d %H:%M:%S') | string}}",
             "state": "closed",
             "location": "postbox",
             "sensor": "{{ trigger.payload_json.RfReceived.Data | string }}",
             "sync": {{ trigger.payload_json.RfReceived.Sync | string}}
           }

I can not figure out where I’m doing it wrong. Can somebody help me with it?
Thanks

The error is telling you that you can not call a service as a part of a condition.

- service: persistent_notification.create

The service calls must come under the actions

You can however have conditions in series with services ( under actions ) but as soon as a condition is false the automation will stop.

action:
  - service:
  - condition:
  - service:
  - condition:
  - condition:
  - service:

If you have multiple instances of an action being conditional on a state, you will need multiple automations or scripts

Many thanks for the help

Correct, that’s what happens.

Does this mean that I have to create an automation script per condition? This would, in my case, mean that I would have to create 32 automations. It would be better if I had only one per sensor. I tried this, but it does not work either.

    alias: postbox_sensor
    initial_state: true
    trigger:
      - platform: mqtt
        topic: "tele/rfbridge/RESULT"
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.RfReceived.Data == "21A8F3" }}'
    - action:
	- service:
          .....
    - action:  
	  - condition:
	  - service:
    - action:  
	  - condition:
	  - service:

You can only have one action block per automation.

Thanks… no it works with script:

automation

.....
action:
  ## ----------------------------------------------
  ## send notification to homeassitant gui
  ## ----------------------------------------------  
  - service: script.appicationmessage
    data:
      message: "Postkasten wurde um {{ now().strftime('%Y-%m-%d %H:%M:%S') }} geöffnet !"
      title: "Security Postkasten"
	
  ## ----------------------------------------------
  ## send notification to all alexa devices
  ## ----------------------------------------------       
  - service: script.alexamessage
    data:
      message: "Hausmeister meldet, Trara, Trara, die Post ist da, es ist etwas im Postkasten."

script

  appicationmessage:
    alias: "Application message"
    sequence:
    - condition: state
      entity_id: input_boolean.enable_sensor_notify
      state: 'on'
    - service: persistent_notification.create
      data_template:
        message: "{{ message }}"
        title: "{{ title }}"
		
  alexamessage:
    alias: "Alexa message security"
    sequence:
    - service: media_player.alexa_tts
      data_template:  
        entity_id:
          - media_player.esszimmer
          - media_player.wohnzimmer
          - media_player.offic
          - media_player.bad
          - media_player.fitnessraum
        message: "{{ message }}"